Reputation: 1067
I'm taking a beginner Computer Science course at my local college and one of the parts of this assignment asks me to convert a hex number to its hex equivalent. We use an online basic computer to do this that takes specific inputs specific inputs.
So according to my Appendix, when I type in a certain code it is supposed to "add the bit patterns [ED] and [09] as though they were two's complement representations." When I type the code into the system, it gives an output of F6... but I have no idea how it got there.
I understand how adding in two's complement works and I understand how to add two normal hex numbers, but when I add 09 (which is supposed to be the hex version of two's complement 9) and ED (which is supposed to be the hex version of two's complement -19), I get 10 if adding in two's complement or 162 if adding in hex.
Upvotes: 0
Views: 2133
Reputation: 16791
Okay, you're just confusing yourself. Stop converting. This is all in hexadecimal:
ED
+ 09
----
D + 9 = 16 // keep the 6 and carry the 1
1
ED
+ 09
----
6
1 + E = F
ED
+ 09
----
F6
Regarding the first step, using 0x to denote hex numbers so we don't get lost:
0xD = 13,
0x9 = 9,
13 + 9 = 22,
22 = 0x16
therefore
0xD + 0x9 = 0x16
Gotta run, but just one more quick edit before I go.
D + 1 = E
D + 2 = F
D + 3 = 10 (remember, this is hex, so this is not "ten")
D + 4 = 11
...
D + 9 = 16
Upvotes: 1