Professional Documents
Culture Documents
Binary Arithmetic PDF
Binary Arithmetic PDF
Decimal (10)
Binary (2)
Octal (8)
Hexadecimal (16)
............
3
Binary numbers?
• Computers work only on two states
– On
– Off
• Basic memory elements hold only two states
– Zero / One
• Thus a number system with two elements
{0,1}
• A binary digit – bit !
4
Decimal numbers
• Radix = 10
5
Binary Decimal
1101 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20
=1x8+1x4+0x2+1x1
=8+4+0+1
(1101)2 = (13)10
2 13 1 LSB
2 6 0
2 3 1
2 1 1 MSB
0
(13)10 = (1101)2
7
Octal Decimal
137 = 1 x 82 + 3 x 81 + 7 x 80
= 1 x 64 + 3 x 8 + 7 x 1
= 64 + 24 + 7
(137)8 = (95)10
8 95 7 LSP
8 11 3
8 1 1
0 MSP
(95)10 = (137)8
9
Hex Decimal
BAD = 11 x 162 + 10 x 161 + 13 x 160
= 11 x 256 + 10 x 16 + 13 x 1
= 2816 + 160 + 13
(BAD)16 = (2989)10
10
Decimal Hex
16 2989 13 LSP
16 186 10
16 11 11
0 MSP
(2989)10 = (BAD)16
11
Why octal or hex?
• Ease of use and conversion
• Three bits make one octal digit
111 010 110 101
7 2 6 5 => 7265 in octal
Three representations
• Signed magnitude
• 1’s complement
• 2’s complement
13
Sign magnitude
• Make MSB represent sign
• Positive = 0
• Negative = 1
• E.g. for a 3 bit set Sign Bit Bit
– “-2”
1 1 0
MSB LSB
14
1’s complement
• MSB as in sign magnitude
• Complement all the other bits
• Given a positive number complement all
bits to get negative equivalent
• E.g. for a 3 bit set
– “-2” (value) Sign Bit Bit
(+2) 0 1 0
(-2) 1 0 1
15
2’s complement
• 1’s complement plus one
• E.g. for a 3 bit set
– “-2”
Sign Bit Bit
(steps) (value)
1.start with
positive # (+2)10 0 1 0
2. make 1’s
comp. (+2) 1 0 1
3. add 1
+1
4. 2’s comp.
(-2) 1 1 0
16
Decimal Signed 1’s complement 2’s complement
number magnitude
3 011 011 011
2 010 010 010
1 001 001 001
0 000 000 000
-0 100 111 ---
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 100
18
Unsigned: Addition
Like normal decimal addition
B
+ 0 1
0101 (5)
A 0 0 1 + 1001 (9)
1 1 (1*) 0 1110 (14)
21
2’s complement
Negative numbers in 2’s complement
001 ( 1)10
101 (-3)10
110 (-2)10
24
Underflow examples
Two’s complement addition
101 (-3)10
101 (-3)10
Carry 1 010 (-6)10 ????