1 / 16

Number Representation

Number Representation. Lecture 20 4.3.2001. 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?. Binary number system.

tavia
Télécharger la présentation

Number Representation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Binary number system 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. • 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 ? 102 * 1 = 100.0 101 * 3 = 30.0 100 * 6 = 6.0 10-1 * 2 = 0.2 10-2 * 5 = 0.05

  5. Binary Number • 1101.01: What does this number mean? 23 * 1 = 1000.0 (8 in decimal) 22 * 1 = 100.0 (4 in decimal) 21 * 3 = 0.0 (0 in decimal) 20 * 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*23 + 0*22 + 0*21 + 0*20) 1 0001 (0*23 + 0*22 + 0*21 + 1*20) 2 0010 (0*23 + 0*22 + 1*21 + 0*20) 3 0011 (0*23 + 0*22 + 1*21 + 1*20) 4 0100 (0*23 + 1*22 + 0*21 + 0*20) 5 0101 (0*23 + 1*22 + 0*21 + 1*20) 6 0110 (0*23 + 1*22 + 1*21 + 0*20) 7 0111 (0*23 + 1*22 + 1*21 + 1*20) 8 1000 (1*23 + 0*22 + 0*21 + 0*20) 9 1001 (1*23 + 0*22 + 0*21 + 1*20)

  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 = Mj=0bj Bj • N: the number • M : Number of digits • b: The digit • B : System’s radix

  9. Examples 1. 101011  1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20 = 43 (101011)2 = (43)10 2. .0101  0x2-1 + 1x2-2 + 0x2-3 + 1x2-4 = .3125 (.0101)2 = (.3125)10 3. 101.11  1x22 + 0x21 + 1x20 + 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 • 239 • 2 119 --- 1 • 59 --- 1 • 2 29 --- 1 • 14 --- 1 • 2 7 --- 0 • 3 --- 1 • 2 1 --- 1 • 2 0 --- 1 (239)10 = (11101111)2

  12. Example 2 :: 64 • 64 • 2 32 --- 0 • 16 --- 0 • 2 8 --- 0 • 4 --- 0 • 2 2 --- 0 • 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

More Related