-1

I'm trying to convert -24 to the hexadecimal representation but I always end up with a decimal of 8 which is incorrect.

Work:

-24 -> 24

24 in binary is: 11000 Now I take the two's complement: 11000 -> 00111 + 1 -> 01000 01000 is 8.

What did I do wrong?

Ayyware
  • 11
  • 2
    You'e acting like there are only $5$ bits in the representation. There are, presumably, other leading $0$ bits that you have to flip. If there actually are only $5$ bits, then what you've done is correct. – saulspatz Jul 06 '20 at 05:38

1 Answers1

1

I think I figured it out. I forgot to add the sign bit which would turn the answer to 101000 which is 40. 40 converted into hex is 0x18 which is correct.

Ayyware
  • 11