Ones compliment
- The term compliment refers to a part which together with another makes up a whole. For example in geometry two complimentary angle (900).
- The idea of compliment is used to address the problem of signed numbers i.e. positive and negative.
- In decimal numbers (0 to 9), we talk of nine’s compliment. For example the nines compliment
- Of 9 is 0, that of 5 is 4 while 3 is 6.
- However, in binary numbers, the ones compliment is the bitwise NOT applied to the number. Bitwise NOT is a unary operator (operation on only one operand) that performs logical negation on each bit. For example the bitwise NOT of 11002 is 00112e.
- 0s are negated to 1s while 1s are negated to 0s.
Twos compliment
- Twos compliment, equivalent to tens compliment in decimal numbers, is the most popular way of representing negative numbers in computer systems. The advantages of using this method are:
- There are no two ways of representing a zero as in the case with other two methods.
- Effective addition and subtraction can be done even with numbers that are represented with a sign bit without a need for circuitries to examine the sign of an operand.
- The twos compliment of a number is obtained by getting the ones compliment then adding a 1. For example, to get the twos compliment of a decimal number 4510,
- First convert it to its binary equivalent then find its ones compliment. Add a 1 to ones compliment i.e.
4510=001011012
Bitwise NOT (00101101) =11010010
Two’s compliment = 110100102+12
= 110100112
Binary addition
The five possible additions in binary are
- 0 + 0 = 0
- 0+ 12 = 12
- 12 + 0 = 12
- 12 + 12 = 102 (read as 0, carry 1)
- 12 + 12 + 12 = 112 (read as 1, carry 1)
Example 1
Find the sum of 1112 + 0112
Solution
Arrange the bits vertically. 111
Working from the right to the left, we proceed as follows: + 011
Step 1 12 + 12 = 102, (write down 0 and carry 1) 10102
Step 2 12 + 12 + 12 = 112, (add and carry over digit to 1 + 1 in order to get 1 + 1
+1. From the sum, write down digit one the carry
Forward)
Step 3 12 + 12 + 02 = 102, (add the carry over digit to 1 + 0 in order to get
1 + 1 + 0.since this is the last step, write down 10)
Therefore 1112 + 0112 = 10102
This can be summarized in the table
1st number
1
1
1
2nd number
0
1
1
Carry digit
-
1
1
sum
10
1
0
Example 2
Add the following binary number
101102
10112
+ 1112
Solution
Add the first two numbers and then add the sum to the third number a follows:
Step 1 Step 2
101102 1000012
+ 10112 + 1112
1000012 1010002