Positional Number Systems M 260 1 5 Decimal
Positional Number Systems M 260 1. 5
Decimal Review • 5049 = 5(1000) + 0(100) + 4(10) + 9(1) • 5049 = 5· 103 + 0· 102 + 4· 101 + 9· 100 place 103 102 101 100 digit 5 0 4 9
Binary Representation • 27 = 16 + 8 + 2 + 1 • 27 = 1· 24 + 1· 23 + 0· 22 + 1· 21 + 1· 20 • 27 = 110112 place 24 23 22 21 20 digit 1 1 0 1 1
Some Binary Representations 010 110 210 310 410 510 610 710 810 910 ? 2 ? 2 ? 2
Some Binary Representations 010 110 210 310 410 510 610 710 810 910 02 12 102 112 1002 1012 1102 1112 10002 10012
Powers of Two 210 29 28 27 26 25 24 23 22 21 20 1024 512 256 128 64 32 16 8 4 2 1
Convert Binary to Decimal 1 1 0 12 210 29 28 27 26 25 24 23 22 21 20 1024 512 256 128 64 32 16 8 4 2 1
Convert Binary to Decimal 1 1 0 12 210 29 28 27 26 25 24 23 22 21 20 1024 512 256 128 64 32 16 8 4 0 0 0 1 32 + 16 + 4 + 1 = 53 1 0 2 1 1 0 1
Convert Decimal to Binary • 20910 = 128 + smaller number • = 1(128) + 81 • = 1(128) + 64 + smaller number • = 1(128) + 1(64) + 17 • = 1(128) + 1(64) + 0(32) + 1(16) + 1 1(128)+1(64)+0(32)+1(16)+0(8)+0(4)+0(2)+1(1) = 1 1 0 0 0 12
Binary Addition 12 + 12 1 02 • • 12 12 + 12 1101 +111
Binary Addition 12 + 12 1 02 • • 12 12 + 12 1 1101 +111 0 carry
Binary Addition 12 + 12 1 02 • • 12 12 + 12 1 1 1101 +111 00 carry
Binary Addition 12 + 12 1 02 • • 12 12 + 12 1 1 1 1101 +111 100 carry
Binary Addition 12 + 12 1 02 • • 12 12 + 12 1 1 1 1101 +111 10100 carry
Subtraction in Decimal System • 1 0 0 010 - 5 810
Subtraction in Decimal System • 9 9 10 1 0 0 010 - 5 810 borrowing
Subtraction in Decimal System • 9 9 10 1 0 0 010 - 5 810 942 borrowing
Subtraction in Binary System • 11000 -1011
Subtraction in Binary System • 0 1 1 10 11000 -1011 borrowing
Subtraction in Binary System • 0 1 1 10 11000 -1011 1101 borrowing
Two’s Complement Arithmetic • Computers often use 2’s complement arithmetic for working with signed numbers • 2’s complement of a in n-bit arithmetic is the binary representation of 2 n – a
Two’s Complement Example • The 8 bit representation of -27 is • ( 28 – 27)10 = 22910 = 1 1 1 0 0 12 • Or flip the bits and add one • -27 = -000110112 • = 11100100 + 1 • = 11100101
Two’s Complement Arithmetic • To subtract, take the two’s complement and then add. • Otherwise just add the binary numbers and throw away any positions greater than 2 n-1. • If -2 n-1 result < 2 n-1 then everything is fine. • Otherwise you have an overflow.
Hexadecimal Representations Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hexadecimal Binary
Hexadecimal Representations Decimal Hexadecimal 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 12 C 13 D 14 E 15 F Binary
Hexadecimal Representations Decimal Hexadecimal Binary 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111
Convert Hexadecimal to Decimal • • • 3 CF 16 = 3(162) + 12(161) + 15(160) = 97510
Convert Hexadecimal to Binary • • • C 50 A 16 C 5 0 A 1100 0101 0000 1010
Convert Binary to Hexadecimal • • 0100 1101 1010 1001 4 D A 9
- Slides: 29