0
\$\begingroup\$

I was programming in 8051 and I faced this problem I had to convert the number -10000 to hexadecimal ( 2 bytes) the answer is 0D8h = #HIGH(-10000) 0F0h =LOW (-10000) but how the answer was found /computed ?

\$\endgroup\$
2
\$\begingroup\$

I have no idea how they arrived at 0x0D8, maybe a typo? 0x0D8 is only 12 bits, not 16, and its leading bit is 0, so it is a positive number.

One way is to do the conversion is the classic: convert 10'000 to hex: 0x2710. Now invert all bits: 0xD8EF. Finally add 1: 0xD8F0.

Another way is to start with 0x0000 and substract 1 (or add 0xFFFF) for 10'000 times (or substract 10'000 in one go, if you can do that). The result is the same: 0xD8F0.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.