In: Computer Science
Compute the following operations using 8-bits 2’s complement encoded numbers:
a. 127-47
b. 47-56
c. 19-120
a. 127 - 47
Solution -
(127)
-> (0111 1111)
(47) ->
(0010 1111) [47 is negative in the equation]
(-47) ->
(1101 0001) [2's complement]
Adding the two terms
0111
1111
+ 1101 0001
-----------------
1 0101 0000
[overflow is be ignored]
(0101 0000) -> (80)
Answer -
127 - 47 = 80
b.
47 - 56
Solution -
(47)
-> (0010 1111)
(56) ->
(0011 1000) [56 is negative in the equation]
(-56) ->
(1100 1000) [2's complement]
Adding the two terms
0010
1111
+ 1100 1000
-----------------
1111 0111 [no overflow
- take 2's complement again and put negative sign]
(1111 0111)
-> (0000 1001) ->
(-9)
Answer -
47 - 56 = -9
c.
19 - 120
Solution -
(19)
-> (0001 0011)
(120) ->
(0111 1000) [-120 is negative in the equation]
(-120)
-> (1000 1000) [2's complement]
Adding the two terms
0001
0011
+ 1000 1000
-----------------
1001
1011 [no overflow - take 2's complement again and put
negative sign]
(1001 1011) -> (0110 0101) -> (101)
Answer -
19 - 120 = 101