Question
Add the following decimal numbers in 2's complement
i) -12 and -18.
11) -14 from +12.
i) -12 and -18.
11) -14 from +12.
Answers
Answered by
GPT 3.5
i) To add -12 and -18 in 2's complement, first convert the decimal numbers to their binary representation:
-12 = (0)1100 in 2's complement
-18 = (1)0002 in 2's complement
Now add the two binary numbers:
01100 (12 in binary representation)
+ 10002 (-18 in 2's complement)
_________________________
1 11110
The result in binary is 11110. Since the most significant bit is 1, indicating that it is a negative number, we convert it back to its decimal representation:
11110 in 2's complement = -30 in decimal
Therefore, -12 + -18 = -30
ii) To subtract -14 from +12, first convert the decimal numbers to their binary representation:
+12 = 01100
-14 = (1)0010 in 2's complement
Now subtract the binary numbers:
01100 (12 in binary representation)
- 10010 (-14 in 2's complement)
________________________
11010
The result in binary is 11010. Since the most significant bit is 1, indicating that it is a negative number in 2's complement, we convert it back to its decimal representation.
11010 in 2's complement = -10 in decimal
Therefore, +12 - (-14) = -10
-12 = (0)1100 in 2's complement
-18 = (1)0002 in 2's complement
Now add the two binary numbers:
01100 (12 in binary representation)
+ 10002 (-18 in 2's complement)
_________________________
1 11110
The result in binary is 11110. Since the most significant bit is 1, indicating that it is a negative number, we convert it back to its decimal representation:
11110 in 2's complement = -30 in decimal
Therefore, -12 + -18 = -30
ii) To subtract -14 from +12, first convert the decimal numbers to their binary representation:
+12 = 01100
-14 = (1)0010 in 2's complement
Now subtract the binary numbers:
01100 (12 in binary representation)
- 10010 (-14 in 2's complement)
________________________
11010
The result in binary is 11010. Since the most significant bit is 1, indicating that it is a negative number in 2's complement, we convert it back to its decimal representation.
11010 in 2's complement = -10 in decimal
Therefore, +12 - (-14) = -10