Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Representation Lecture 20 4.3.2001.. Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.

Similar presentations


Presentation on theme: "Number Representation Lecture 20 4.3.2001.. Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is."— Presentation transcript:

1 Number Representation Lecture 20 4.3.2001.

2 Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is allocated for each type of data? int, float, char, etc. How are characters and strings stored in memory?

3 Decimal number system Ten digits : 0,1,2,3,4,5,6,7,8,9 Every digit position has a weight which is a power of 10. Base or radix is 10. Binary number system Two digits : 0,1 Every digit position has a weight which is a power of 2. Base or radix is 2.

4 Decimal Number 136.25 : What does this number actually mean ? 10 2 * 1 = 100.0 10 1 * 3 = 30.0 10 0 * 6 = 6.0 10 -1 * 2 = 0.2 10 -2 * 5 = 0.05

5 Binary Number 1101.01: What does this number mean? 2 3 * 1 = 1000.0 (8 in decimal) 2 2 * 1 = 100.0 (4 in decimal) 2 1 * 3 = 0.0 (0 in decimal) 2 0 * 6 = 1.0 (1 in decimal) 2 -1 * 2 = 0.0 (0.0 in decimal) 2 -2 * 5 = 0.01 (0.25 in decimal)

6 First integers and their binary equivalent decimal binary 0 0000 (0*2 3 + 0*2 2 + 0*2 1 + 0*2 0 ) 1 0001 (0*2 3 + 0*2 2 + 0*2 1 + 1*2 0 ) 2 0010 (0*2 3 + 0*2 2 + 1*2 1 + 0*2 0 ) 3 0011 (0*2 3 + 0*2 2 + 1*2 1 + 1*2 0 ) 4 0100 (0*2 3 + 1*2 2 + 0*2 1 + 0*2 0 ) 5 0101 (0*2 3 + 1*2 2 + 0*2 1 + 1*2 0 ) 6 0110 (0*2 3 + 1*2 2 + 1*2 1 + 0*2 0 ) 7 0111 (0*2 3 + 1*2 2 + 1*2 1 + 1*2 0 ) 8 1000 (1*2 3 + 0*2 2 + 0*2 1 + 0*2 0 ) 9 1001 (1*2 3 + 0*2 2 + 0*2 1 + 1*2 0 )

7 Adding Binary Numbers Basic Rules: 0+0=0 0+1=1 1+0=1 1+1=0 (carry 1) Example: 01101001 00110100 ------------- 10011101

8 Weighted number systems N =  M j=0 b j B j N: the number M : Number of digits b: The digit B : System’s radix

9 Examples 1. 101011  1x2 5 + 0x2 4 + 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 = 43 (101011) 2 = (43) 10 2..0101  0x2 -1 + 1x2 -2 + 0x2 -3 + 1x2 -4 =.3125 (.0101) 2 = (.3125) 10 3. 101.11  1x2 2 + 0x2 1 + 1x2 0 + 1x2 -1 + 1x2 -2 5.75 (101.11) 2 = (5.75) 10

10 Decimal-to-Binary Conversion Consider the integer and fractional parts separately. For the integer part, Repeatedly divide the given number by 2, and go on accumulating the remainders, until the number becomes zero. Arrange the remainders in reverse order. For the fractional part, Repeatedly multiply the given fraction by 2. Accumulate the integer part (0 or 1). If the integer part is 1, chop it off. Arrange the integer parts in the order they are obtained.

11 Example 1 :: 239 2239 2 119 --- 1 2 59 --- 1 2 29 --- 1 214 --- 1 2 7 --- 0 2 3 --- 1 2 1 --- 1 2 0 --- 1 (239) 10 = (11101111) 2

12 Example 2 :: 64 2 64 2 32 --- 0 2 16 --- 0 2 8 --- 0 2 4 --- 0 2 2 --- 0 2 1 --- 0 2 0 --- 1 (64) 10 = (1000000) 2

13 Example 3:.634.634 x 2 = 1.268.268 x 2 = 0.536.536 x 2 = 1.072.072 x 2 = 0.144.144 x 2 = 0.288 : (.634) 10 = (.10100……) 2

14 Example 4: 37.0625 (37) 10 = (100101) 2 (.0625) 10 = (.0001) 2  (37.0625) 10 = (100101.0001) 2

15 Hexadecimal Numbers Base=16 Decimal Binary Hex 0 00000 0 1 00001 1 2 00010 2 3 00011 3 4 00100 4 5 00101 5 6 00110 6 7 00111 7 8 01000 8 9 01001 9 Decimal Binary Hex 10 01010 10 11 01011 11 12 01100 12 13 01101 13 14 01110 14 15 01111 15 16 00110 16 17 00111 17 18 01000 18 19 01001 19

16 Integers Representation


Download ppt "Number Representation Lecture 20 4.3.2001.. Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is."

Similar presentations


Ads by Google