2’s Complement Hexadecimal Addition

AI Thread Summary
The discussion clarifies the addition of hexadecimal values, specifically 0xD and 0x9, which equals 0x16. It explains that 0xD represents 13 in decimal and 0x9 represents 9, leading to a decimal sum of 22. The confusion arises from interpreting 22 as equal to 0x16, which is incorrect in a direct sense. Instead, the hexadecimal notation is crucial; 0x16 in hexadecimal equals 22 in decimal. The conversation emphasizes the importance of understanding the distinction between hexadecimal and decimal systems, highlighting that 0x10 equals 16, and thus 0x16 is equivalent to 22 in decimal terms.
siid14
Messages
1
Reaction score
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
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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top