Question about hexadecimal.

Hi,

From what I remember two's complement is used to present negative numbers. If you take 19 as binary:

Code:
128    64    32    16    8    4    2    1    (bits)
 0     0      0    1     0    0    1    1

To convert to the negative number (-19) use two's complement. Invert the bits and add one:

Code:
128    64    32    16    8    4    2    1    (bits)
 1     1     1      0    1     1    0    1

In hex the above is ED, the most significant bit being used as the sign.

Regards,
Jim
 
Last edited:
To extend on JIMA's post a bit,

Firstly, with two's complement it's always worth remembering how it actually stores the number, which is that the most siginificant bit is the same value but negative, so in this case the 7th bit (128) actually represents -128,

So instead of an 8-bit value being able to store 0-255, it can now store -128 to 127.

Then with the conversion to Hexadecimal, not sure how much you know, but hexadecimal can store 0-15 in a single digit, using 0-9 and then A-F. This allows you to store more data in a smaller number of digits.

When converting binary to hex you take a group of 4 bits to convert to a single hexadecimal digit, so again looking at the bit pattern for -19 (using twos complement):

1110 and 1101, or in decimal 14 and 13, or in Hex E and D.

Hopefully that isn't too patronising and is actually helpful :p
 
Back
Top Bottom