Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 198: Lecture 4: Data Representation

Similar presentations


Presentation on theme: "CSCI 198: Lecture 4: Data Representation"— Presentation transcript:

1 CSCI 198: Lecture 4: Data Representation

2 Running the program Wrong result! What happen? A run:
please input two numbers: num1 = 2 num2 = 3 the sum is 5 Another run: num1 = 450 num2 = 300 the sum is 750 One more time please input two numbers: num1 = num2 = the sum is Wrong result! What happen?

3 Data Representation

4 Decimal Number Systems
Base 10 Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 e.g = = 3 x x x100 = 3 x x x 1 =

5 Binary Number System Base 2 Digits 0, 1 e.g. 1102 =
= 1 x x x 20 = 1 x x x 1 = = 6

6 Counting in Binary Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110
Decimal Binary

7 Addition 0+ 0 1 + 0 0 + 1 1 + 1

8 How many symbol can N digit represent?
3 digit allows representing 8 numbers (symbols): 0-7 : – 15 N N

9 16-bit Memory Word To store number 6, use 0000000000000110
Value 0 is Largest value is = 65,535 = 216 − 1 32-bit word gives largest value > 4 billion

10 Number of bits How many states can be represented with 1 bits, 2 bits, 3 bits, 8 bits …. To represent N states, how many bits are needed: log2N

11 Character Representation
1 byte = 8 bits = 1 character? 256 possible codes with 8 bits Assign a character to each code Common assignment ASCII - American Standard Code for Information Interchange – defines first 128

12 ASCII Code Code Value Letter 0 Null character
Special Control Characters 10 \n = New line 32 Space 33-47, 58-64, Punctuation A - Z a - z

13 Interesting ASCII Choice?
Digits 0 through 9 seem strange? Digit Dec Hex … … …

14 Unicode International language coding standard Superset of ASCII
Various codes defined to use upper 128 bits for symbols in other languages

15 Storing Negative Values Two’s complement!

16 Two’s Complement Two’s complement if positive, use binary
if negative, complement bits and add one e.g. −53 magnitude complement add

17 Overflow In 16-bit two’s complement, what happens if we add −32,

18 Large and Small Numbers
On 9-digit calculator, = 1.0 E 9 In binary, = 1.0 x 28 Small numbers, = ½10 = 0.12 = 1.0 x 2-1

19 Real Numbers in Binary 0.11011 x 24 = 1101.1 = 8 + 4 + 1 + 0.5 = 13.5
In 16-bit word, sign mantissa exponent

20 Converting Decimal to Binary
Repeatedly divide by 2, recording remainders in reverse order e.g. 53 / 2 = 26 R 1 26 / 2 = 13 R 0 13 / 2 = 6 R 1 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 giving

21 Converting Binary to Decimal
Repeatedly multiply by 2 and add next bit e.g = 1* * *21 + 1*20


Download ppt "CSCI 198: Lecture 4: Data Representation"

Similar presentations


Ads by Google