Hexadecimal value of a negative number?

$\begingroup$

How can I find the hexadecimal value of negative number? I was studying from a slide that shows these values and there hexa's...!

-3 = FDH
-12 = F4H
-48 = D0H
-200 = 38H

How?

$\endgroup$ 1

3 Answers

$\begingroup$

They are using two's complement notation to represent negative numbers. To get it, you start with your value, express it in binary, change all the 0's to 1's and vice versa, then add 1. You can do it directly in hex, subtracting each digit from 15, then adding 1. It would be clearer what is going on if you convert the numbers on the left (which are in decimal) to hex, so $200_{10}=C8H$ and $C8H+38H=0H$. It has the advantage that you can add, subtract, and multiply without worrying about the signs. There are other notations.

$\endgroup$ $\begingroup$

It is answered by Ross how to do this. I'd also like to point out that -3 = FDh for 8 bit representation. What do I mean by 8-bit representation? Well decimal three is just 11 in binary, but that is 2-bit representation. 8 bit representation is 0000 0011. So, to do the two's complement of that, invert all the bits and add 1 as follows: 1111 1100 + 1 = 1111 1101 which corresponds to FD in hex.

What about -200? Why is it represented in the given problem as 38h? Well, that's because they are representing -200 using 6 bits for some reason (either to conserve bits, or perhaps to try to confuse you). First of all, positive 200 can't even be represented using 6 bits. 200 would be 1100 1000 and to get -200, we do the two's complement: 0011 0111 + 1 = 0011 1000 and if you truncate to the lower 6 bits, you'll get 11 1000, which is 38 in hex.

The reason why one might say this is sloppy is because of a few reasons: -200 cannot correctly be handled with an 8-bit two's complement system because two's complement handles a range from -128 to +127. [A rule to remember is that the most significant bit (MSB) of negative numbers in two's complement is always 1]. Also, as previously mentioned, it should be explicitly stated how many bits you're using and what method is being used to represent negative numbers (2's complement).

I'd prefer to write -200 as a 16-bit number: 11111111 00111000 of FF38 because a 16-bit system readily handles operations of a number that large (-32,768 to 32,767).

$\endgroup$ 3 $\begingroup$

Change the number into $8$ bit binary number then take $2$'s complement; you will get the hexadecimal of negative number.

e.g., for $-3$ change into binary: $00000011$ take $2$'s complement: $11111101=FD$ (hex)

$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like