How to tell if hex value is negative?

后端 未结 4 1230
野趣味
野趣味 2020-12-16 17:57

I have just learned how to read hexadecimal values. Until now, I was only reading them as positive numbers. I heard you could also write negative hex values.

My issu

4条回答
  •  盖世英雄少女心
    2020-12-16 18:54

    From what I understand, you always need to look at the left-most digit to tell the sign. If in hex, then anything from 0-7 is positive and 8-f is negative. Alternatively, you can convert from hex to binary, and if there's a 1 in the left-most digit, then the number is negative.

    HEX <-> BINARY <-> SIGN
    0-7 <-> 0000-0111 <-> pos
    8-F <-> 1000-1111 <-> neg

提交回复
热议问题