Corey McGlone wrote:Barry's absolutely correct.
How do you know if a binary number is negative? You look at the most significant bit (the sign bit) to see if it is a 1 or a 0. If it's a 1, you have a negative number. If it's a 0, it's positive.
So how does this translate to hex? Well, like Barry said, every hexadecimal digit is equivalent to 4 binary digits. So, take the most significant hexadecimal digit and determine if the binary bits it represents start with a 1 or not. In hex, anything 8 or greater starts with a 1 so, if your hexadecimal number starts with a digit greater than or equal to 8, it's negative. If it's 0 through 7, it's positive.
Tim Moores wrote:A hex number is always positive (unless you specifically put a minus sign in front of it). It might be interpreted as a negative number once you store it in a particular data type. Only then does the most significant bit (MSB) matter, but it's the MSB of the number "as stored in that data type". In that respect the answers above are only partially correct: only in the context of an actual data type (like an int or a long) does the MSB matter.
If you store "0xdcafe" in an int, the representation of it would be "0000 0000 0000 1101 1100 1010 1111 1110" - the MSB is 0. Whereas the representation of "0xdeadcafe" is "1101 1110 1010 1101 1100 1010 1111 1110" - the MSB is 1.