In: Computer Science
Convert decimal +47 and +31 to binary, using the signed-2’s-complement representation and enough digits to accommodate the numbers. Then perform the binary equivalent of (+31)+(-47), (-31)+(+47), and (-31)+(-47). Convert the answers back to decimal and verify that they are correct.
(+31) + (-47) = -16
(-31) + (+47) = 16
(-31) + (-47) = -78
Explanation:
47 in binary = 1011112
31 in binary = 111112
Let the signed number system be of 8 bit then
47 = 0010 1111
31 = 0001 1111
-47 = 1101 0001 (in 2's compliment)
-31 = 1110 0001 (in 2's compliment)
Conversion to 2's compliment explanation:
first convert decimal number to binary here 47 = 0010 1111
since the number is negative convert it to 1's compliment just flip the bits 1 to 0 and 0 to 1
1's compliment: 1101 0000
add 1 to 1's compliment we get 2's compliment
1101 0000 + 1
1101 0001
2's compliment conversion is same for -31 as well
Coming to questions:
(+31) + (-47) = -16
+31 = 0001 1111
-47 = 1101 0001
(+31) + (-47) =
= .1111 0000
since the MSB is 1 hence the number is negative. converting it to 2' compliment we get 0001 0000
in decimal 0001 0000 = 16 Since MSB is 1 hence it is -16
(-31) + (+47) = 16
-31 = 1110 0001
+47 = 0010 1111
(-31) + (+47) =
= 0001 0000
since MSB is 0 the number is positive no need for 2's compliment: 0001 0000 in decimal is 16
(-31) + (-47) = -78
-31 = 1110 0001
-47 = 1101 0001
(-31) + (-47) =
= 1011 0010
Since MSB is 1 hence the number is negative convert it to 2's compliment we get 0100 1110
In decimal it is -78.