a) 18
- A positive number is the same in unsigned form and also in
two's complement form.
- To find the two's complement form of a positive number, just
represent the decimal integer in its binary form
- Convert 18 to binary
- 18/2 9 - 0
- 9/2 4 - 1
- 4/2 2 - 0
- 2/2 1 - 0
- The binary equivalent of 18 is 10010 and when it
represented in 6 bits, it is 010010
- Two's complement of 18 is same as the positive
notation.
- Answer is
0100102
=============================================================================================
b) -12
- To find the two's complement form of a negative number, first
represent the decimal integer in its binary form
- Invert all the bits in the binary ,which means convert 1's to
0's and 0's to 1's
- Add 1 to the Inverted answer
- The resultant binary number is the two's complement
representation of the decimal integer.
- Convert 12 to binary
- 12/2 6 - 0
- 6/2 3 - 0
- 3/2 1 - 1
- 1/2 0 - 1
- The binary equivalent of 12 is 01100 and when it
represented in 6 bits, it is 001100
- Invert the bits and the result is 110011
- Add 1 to this result. 110011+1 =>
110100
- Two's complement of -12 is 110100
- Answer is
1101002
Below diagram shows the addition of 110011 and
1
The first row specifies the carry and the last row
specifies the sum.
1+1 = sum (0) carry (1)
0+1 = sum(1) carry (0)
1+0 = sum(1) carry (0)
0+0 = sum(0) carry(0)
|
|
|
1 |
1 |
|
|
1 |
1 |
0 |
0 |
1 |
1 |
+ |
|
|
|
|
|
1 |
= |
1 |
1 |
0 |
1 |
0 |
0 |
sum |