View
221
Download
2
Category
Preview:
Citation preview
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 Representations010 02
110 12
210 102
310 112
410 1002
510 1012
610 1102
710 1112
810 10002
910 10012
Convert Binary to Decimal
210 29 28 27 26 25 24 23 22 21 20
1024 512 256 128 64 32 16 8 4 2 1
1 1 0 1 0 12
Convert Binary to Decimal
210 29 28 27 26 25 24 23 22 21 20
1024 512 256 128 64 32 16 8 4 2 1
0 0 0 0 0 1 1 0 1 0 1
1 1 0 1 0 12
32 + 16 + 4 + 1 = 53
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) + 11(128)+1(64)+0(32)+1(16)+0(8)+0(4)+0(2)+1(1)
= 1 1 0 1 0 0 0 12
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 2n – a
Two’s Complement Example
• The 8 bit representation of -27 is
• ( 28 – 27)10 = 22910
= 1 1 1 0 0 1 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 2n-1.
• If -2n-1 result < 2n-1 then everything is fine.
• Otherwise you have an overflow.
Hexadecimal RepresentationsDecimal Hexadecimal Binary
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
Hexadecimal RepresentationsDecimal 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
Recommended