I need to encode a signed integer as hexadecimal using via the two's complement notation. For example I would like to convert
e.g. -24375 to 0xffffa0c9.
So far I have been working on the following lines:
parseInt(-24375).toString(2)
> "-101111100110111"
This matches what Wolfram Alpha displays, but I am not sure how to get to the signed 24bit int representation of the number (ffffa0c9).
I've worked out how to take the unsigned binary number and represent this as two's complement:
~ parseInt("101111100110111", 2) + 1
> -23475
but I am not sure get the binary representation of this number to convert to hex.
Any ideas?