How to tell if hex value is negative?

Read up on Two’s complement representation: https://en.wikipedia.org/wiki/Two%27s_complement

I think that the easiest way to understand how negative numbers (usually) are treated is to write down a small binary number and then figure out how to do subtraction by one. When you reach 0 and apply that method once again – you’ll see that you suddenly get all 1’s. And that is how “-1” is (usually) represented: all ones in binary or all f’s in hexadecimal. Commonly, if you work with signed numbers, they are represented by the first (most significant) bit being one. That is to say that if you work with a number of bits that is a multiple of four, then a number is negative if the first hexadecimal digit is 8,9,A,B,C,D,E or F.

The method to do negation is:

  1. invert all the bits
  2. add 1

Another benefit from this representation (two’s complement) is that you only get one representation for zero, which would not be the case if you marked signed numbers by setting the MSB or just inverting them.

Leave a Comment