I'm sure it's obvious as day, but i'm having a hard time convincing myself with all these carries and conversions...
Given that i'm operating on the same number (say, 0xA451
) in different representations(0x and 0b), is it always safe to use "16's complement" (not an actual term) to represent the opposite number instead of "going down" to binary and using two's complement?
I.e. I want to know what minus 0xA451
is so i do (0xFFFF - 0xA451) + 0x0001
= 0x5baf
.
Else, i could have done 0xA451 = 1010 0100 0101 0001
, flip them bits and add one:
0101 1011 1010 1110
+
0000 0000 0000 0001
=
0101 1011 1011 0000
, which is indeed 0x5baf
.
I would appreciate somebody confirming that this is always true.