How to Convert Negative Numbers to Binary

••• scyther5/iStock/GettyImages

Because the binary number system has only two symbols--1 and 0--representing negative numbers is not as simple as adding a minus sign in front. There are, however, simple ways to represent a negative number in binary. This article will offer three solutions to that problem.

Use a Sign Bit

    Select the number of bits you will use to represent your binary numbers. An eight-bit number has been long used as a standard. It was the original size for an integer in computer programming. Of course, there are also long integers (16 bits). Note: if you use an eight-bit integer, then only seven bits will be used to represent your actual number.

    Select the leftmost bit to serve as a sign bit. If the bit is 0, the number is positive. If it is 1, the number is negative.

    Write your negative number using all eight bits. Therefore the number -5 would be written as 10000101.

Using 1s Compliment

    Write the number in binary as you would if it were positive. Again, write 5 as 00000101, assuming we are using eight-bit integers.

    Invert the digits--i.e. 1s go to 0s and 0s go to 1s. Therefore, 5 becomes 11111010.

    Use the leftmost bit as the sign bit. So just as with using a sign bit, positive numbers will all have a 0 leading bit (when written in an 8 bit format) while all negative numbers will contain a leading 1. To use the number, use the sign bit information and flip the digits back for numerical value.

Using 2s Compliment

    Write the number as you would as if it were positive, using all eight bits. So 5 is 00000101.

    Invert the bits, switching the 1s and 0s as you did with 1s compliment. So, again, 5 becomes 11111010.

    Add 1 to your number. So 5 becomes 11111010 + 00000001 = 11111011.

    Check your answer. The number 11111011 would be, converted back to base 10: -128 + 64 + 32 + 16 + 8 + 0 + 2 + 1 = -5.

References

Dont Go!

We Have More Great Sciencing Articles!