-1
$\begingroup$

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?

$\endgroup$
1
  • 2
    $\begingroup$ 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. $\endgroup$
    – saulspatz
    Commented Jul 6, 2020 at 5:38

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .