2’s Complement Hexadecimal Addition

In summary, The solution (green arrow) states that for example : 0xD + 0x9 = 0x16, which can also be written as 13 + 9 = 22. The 0x prefix is important in hexadecimal notation, and 0x16 is equivalent to 22 in decimal notation.
  • #1
siid14
1
0
TL;DR Summary
Working on 2's Complement Hexadecimal but still don't get the addition. I was looking at the post here: https://stackoverflow.com/questions/33322671/how-to-add-hex-numbers-using-twos-complement
The solution (green arrow) states that for example :

0xD + 0x9 = 0x16

Details :

0xD = 13,
0x9 = 9,
13 + 9 = 22,
22 = 0x16

Where does the 0x16 come from? I do get to add D + 9 = 13 + 19 = 22 so how come 22 is equal to 16 (assuming D + 9 = 16 is correct) How am I suppose this solution?
 
Technology news on Phys.org
  • #2
siid14 said:
Where does the 0x16 come from? I do get to add D + 9 = 13 + 19 = 22 so how come 22 is equal to 16 (assuming D + 9 = 16 is correct) How am I suppose this solution?
D + 9 is not meaningful, and 22 is obviously not equal to 16. The 0x prefix is vital.

We can write 0xD + 0x9 = 0x16 in hexadecimal, or we can write 13 + 9 = 22 in decimal, or we can even write 0xD + 0x9 ≡ 22 (note the use of the ≡ sign here to show equivalence as opposed to equality).

Note that 0x10 ≡ 16, so 0x16 = 0x10 + 0x6 ≡ 16 + 6 = 22.
 
Last edited by a moderator:

FAQ: 2’s Complement Hexadecimal Addition

How do you add two's complement hexadecimal numbers?

To add two's complement hexadecimal numbers, you simply perform regular hexadecimal addition and discard any carry out of the most significant bit. If the result exceeds the range of the hexadecimal representation, wrap around to the lowest value in the range.

What is the purpose of using two's complement in hexadecimal addition?

Two's complement is used to represent negative numbers in binary and hexadecimal systems. It simplifies arithmetic operations by allowing addition and subtraction to be performed using the same algorithms as for positive numbers.

How do you represent negative numbers in two's complement hexadecimal?

To represent negative numbers in two's complement hexadecimal, invert all bits of the positive number, add 1 to the result, and then perform regular hexadecimal addition with the negative number.

Can two's complement hexadecimal addition result in overflow?

Yes, two's complement hexadecimal addition can result in overflow. Overflow occurs when the sum of two numbers exceeds the maximum positive value that can be represented in the hexadecimal system.

How do you handle overflow in two's complement hexadecimal addition?

To handle overflow in two's complement hexadecimal addition, you can discard the carry out of the most significant bit or use additional bits to represent the overflow. Alternatively, you can check for overflow during the addition process and adjust the result accordingly.

Back
Top