Signed Binary Number
Representation
1's complement and 2's
complement Signed Magnitude
Form
Sign Bit
• To store integers, the (MSB) Most Significant Bit is used to
represent the sign.
• The value of the sign bit:
• 0 - will represent a positive number (+)
• 1 - will represent a negative number (-)
Sign-Magnitude Integers
• Representations To negate a number,
toggle the sign bit.
• 01111binary 15decimal
• 11111 -15 Left-bit encodes sign:
0 = + (or 0)
• 00000 0 1 = - (or 0)
• 10000 -0
• Range
-(2(n-1)-1) to 2(n-1)-1
• Problems
• Two representations of zero (+0 and –0)
• Negation/absolute value operations are easy, but
addition/subtraction operations are difficult.
1’s Complement Integers
• Representations
To negate a number,
• 00110binary 6decimal invert number bit-by-bit.
• 11001 -6 Left-bit encodes sign:
• 00000 0 0 = + (or 0)
• 11111 -0 1 = - (or 0)
• Range
• -(2(n-1)-1) to 2(n-1)-1
• Problems
• Two representations of zero (+0 and –0)
• Arithmetic circuits use binary addition with end-around
carry (ie. resulting carry out of the most significant bit of the
sum is added to the least significant bit of the sum.)
2’s Complement Integers
• Representation To negate a number,
• 00110binary 6decimal 1’s complement + 1.
• 11010 -6 Left-bit encodes sign:
• 00000 0 0 = + (or 0)
1 = -
• 11111 -1
• Range
• –2(n-1) to 2(n-1)-1
• Simplifies logic circuit construction
• Addition is performed using simple binary addition
• Bottom line: simpler/faster hardware units!
2’s Complement Integer
• If number is positive or zero,
• normal binary representation
• If number is negative,
• start with positive number
• flip every bit (i.e., take the one’s complement)
• then add one
00101 (5) 01001 (9)
11010 (1’s comp) 10110 (1’s comp)
+ 1 + 1
11011 (-5) 10111 (-9)
2’s Complement
One such technique is to simply change each bit to its opposite, and then
add 1.
To find the 2’s complement notation for -5:
Represent +5 in fixed length
2’s Complement
One such technique is to simply change each bit to its opposite, and then
add 1.
To find the 2’s complement notation for -5:
Represent +5 in fixed length 00000101
2’s Complement
One such technique is to simply change each bit to its opposite, and then
add 1.
To find the 2’s complement notation for -5:
Represent +5 in fixed length 00000101
“flip the bits” (1 → 0, 0 → 1) 11111010
2’s Complement
One such technique is to simply change each bit to its opposite, and then
add 1.
To find the 2’s complement notation for -5:
Represent +5 in fixed length 00000101
“flip the bits” (1 → 0, 0 → 1) 11111010
add 1 to the new pattern +1
to produce -5 11111011
Review: Numbers…
Signed 1’s 2’s
Un-signed Magnitude Complement Complement
7 111
6 110 10110 = 101
5 101
4 100
3 011 011 011 011
2 010 010 010 010
1 001 001 001 001
0 000 000, 100 000, 111 000
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 100
Range: 0 to 7 -3 to 3 -3 to 3 -4 to 3
Review: Numbers…
Signed 1’s 2’s
Un-signed Magnitude Complement Complement
7 111
6 110 101unsigned = 5
5 101
4 100
3 011 011 011 011
2 010 010 010 010
1 001 001 001 001
0 000 000, 100 000, 111 000
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 100
Range: 0 to 7 -3 to 3 -3 to 3 -4 to 3
Review: Numbers…
Signed 1’s 2’s
Un-signed Magnitude Complement Complement
7 111
6 110 101signed magnitude = -1
5 101
4 100
3 011 011 011 011
2 010 010 010 010
1 001 001 001 001
0 000 000, 100 000, 111 000
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 100
Range: 0 to 7 -3 to 3 -3 to 3 -4 to 3
Review: Numbers…
Signed 1’s 2’s
Un-signed Magnitude Complement Complement
7 111
6 110 1011’s complement = -2
5 101
4 100
3 011 011 011 011
2 010 010 010 010
1 001 001 001 001
0 000 000, 100 000, 111 000
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 100
Range: 0 to 7 -3 to 3 -3 to 3 -4 to 3
Review: Numbers…
Signed 1’s 2’s
Un-signed Magnitude Complement Complement
7 111
6 110 1012’s complement = -3
5 101
4 100
3 011 011 011 011
2 010 010 010 010
1 001 001 001 001
0 000 000, 100 000, 111 000
-1 101 110 111
-2 110 101 110
-3 111 100 101
-4 100
Range: 0 to 7 -3 to 3 -3 to 3 -4 to 3
Binary Arithmetic: Addition
• Base 2 addition – just like base 10!
• add from right to left, propagating carry
carry
10010 10010 1111
+ 1001 + 1011 + 1
1 1 0 1 1 1 1 1 0 1 1 0 0 0 0
10111
+ 111
1 1 1 1 0
Binary
Subtraction
Computers have trouble performing subtractions so the following rule
should be employed:
“X –X is the same as X + -X”
This is where two’s complement is used.
Convert the number to binary.
Perform two’s complement on the negative number.
Add both numbers together.
Binary Subtraction
Take the 2’s complement of the negative number and use regular binary
addition.
9 00001001
+ (-5) + 11111011
4 1]00000100
8th Bit = 0: Answer is Positive
Disregard 9th Bit
00000101
2’s
11111010 Complement
Process
+1
11111011
Binary
Division
Complete the following: 25/5
Step 1: Convert both numbers to binary:
25 = 1 1 0 0 1
5=101
Step 2: Place the numbers accordingly:
101 11001
Binary
Division
Step 3:
Determine if 1 0 1 (5) will fit into the first bit of dividend.
101 11001
1 0 1(5) will not fit into 1(1)
Step 4:
Place a zero above the first bit and try the next bit.
Binary
Division
Step 5: Determine if 1 0 1 (5) will fit into the next two bits of dividend.
0
101 11001
1 0 1(5) will not fit into 1 1(3)
Step 6: Place a zero above the second bit and try the next bit.
Binary
Division
Step 7:
Determine if 1 0 1 (5) will fit into the next three bits of dividend.
0 0
101 11001
1 0 1(5) will fit into 1 1 0(6)
Step 8:
Place a one above the third bit and times it by the divisor (1 0 1)
Binary
Division
Step 9: The multiplication of the divisor should be placed under the THREE bits you have used.
0 0 1
101 11001
101
A subtraction should take place, however you
cannot subtract in binary. Therefore, the two’s
complement of the 2nd number must be found and
the two numbers added together to get a result.
Binary
Division
0 0 1
101 11001 Step 10: The two’s complement of 1 0 1 is 0 1 1
+ 011
001
Binary
Division
Step 12: 1 01 does not fit into 0 0 1 0. Therefore, a zero is placed above the last bit. And the next
number is used.
00 1 0
101 11001
+ 011
00101
Binary
Division
Step 13: 1 0 1 does fit into 1 0 1 so therefore, a one is placed above the final number and the
process of shift and add must be continued.
0 0 1 01
101 11001
+ 011
00101
+ 0 1 1
000
Binary Division by addition
21 ÷ 7 = ?
21 00010101
7 00000111 + 11111001
11111000 1 00001110
+1 + 11111001
-7 11111001 10 00000111
+ 11111001
quotient
11 00000000
remainder