0

I'm trying to understand what a two byte hexadecimal value would look like. As an example, we have the decimal values 41 and -73 with their two-byte binary equivalents:

dec

41 -binary: 000000 00101001

-73 -binary: 11111111 10110111

The hex should then be 29(base16) and 49(base16) respectively. How are these hex values represented in a "two byte" value. Am I doing something wrong here?

thanks

4
  • 1
    For the -73, you would need to do a sign extension to get 11111111 10110111 in binary. 41 in hex would be 0x0029 and -73 would be 0xFFB7. 0x0049 would be +73.
    – eigenchris
    Mar 4, 2015 at 0:51
  • Ahh that's exaclty the answer. Thank you!
    – Chizx
    Mar 4, 2015 at 1:02
  • For -73 -> signed hex, why is the last value 7? I thought you did 15-number to get complements? If you subtract 15 from every value it should be 0xFFB6?
    – Chizx
    Mar 4, 2015 at 1:17
  • That would be 16-number. Personally I find the easiest way to perform 2's complement is by flipping all the bits and adding one. That way a +73 0000 0000 0100 1001 would become a -73 like so: 1111 1111 1011 0110+1. You can then see, looking at the groups of 4 bits, we get F F B 7.
    – eigenchris
    Mar 4, 2015 at 1:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.