How to Convert Negative Numbers to Binary

••• scyther5/iStock/GettyImages

You have almost certainly heard of negative numbers. If you've had even a little exposure to the world of computer science and computer programming, the concept of binary numbers is not entirely foreign. But unless you have explored the programming world personally, you have probably never worked substantively with binary numbers.

Because computers cannot "think" or "decide" on their own but can follow ordered instructions with unfailing accuracy, mathematicians long ago came up with a way for computers (or sufficiently patient humans) to do addition, subtraction and other mathematical operations using only the digits 0 and 1.

But is there a way to combine these two ideas to produce negative numbers? Is it as simple as telling a machine to stick a small horizontal bar in front of an existing number a la pen and paper, or does the "bits and bytes" factor make things more involved?

What Are Binary Numbers?

Computers have an enormous amount of processing power, and even an old clunker can perform computations at a rate that would seem incomprehensible to even the most arithmetically gifted human being. But they are not brains, and the only way to get them to handle complex information is to relegate everything possible to one of two states, e.g., ON or OFF.

In "computer-ese," a single 0 or 1 is referred to as a bit. Groups of these include the nybble (4 bits), the well-known byte (8), the word ( 1) and the long word (32).

The decimal numbers you typically see, like 492 and 35, are "base-10," because they include 10 progressive symbols (the digits 0 through 9) that "roll over" to the next place leftward — the next "power of 10." Binary numbers, instead, include only two symbols (the digits 0 and 1) and are "base-2." Each leftward move from the end of the number is an increasing power of two: The end digits represent 1, the next 2, then 4, 8, 16 and so on.

  • A decimal number is any number in the base-10 system, not necessarily a number that includes a decimal point.

Examples of Binary Numbers

The binary "nybble" 0101 has 1's in the 1 place and the 4 place, and 0's in the 2 and the 8 place. Thus its decimal equivalent is 1 + 4 = 5.

Similarly, the byte 1001 1100 is equivalent to 128 + 16 + 8 + 4 (28 + 25 + 24 + 23) = 156.

The complement of a binary number is just the number with its digits "switched." For example, the complement of 1001 1100 = 0110 0011.

Converting Negative Numbers to Binary

How you convert a negative decimal number to a binary number is probably quite unlike other numerical conversions you have performed because your mind, for all its comparative sloth, is a lot more flexible in most ways than any CPU. However, it is a straightforward process.

The conversion is done using a two's complement binary, which requires the programmer to instruct the computer to interpret any binary number starting with 1 as negative. The program then constructs the corresponding positive number in binary, takes its complement and adds one.

For example, given the number −47, the computer would create the binary number for +47:

0001 1111

The complement of this is:

1110 0000

Adding one to this gives:

1110 0001

Note that the computer has "signed" these numbers to treat a leading 1 as negative and process the results differently than simply adding up the powers of 2 occupied by the symbol 1.

References

About the Author

Kevin Beck holds a bachelor's degree in physics with minors in math and chemistry from the University of Vermont. Formerly with ScienceBlogs.com and the editor of "Run Strong," he has written for Runner's World, Men's Fitness, Competitor, and a variety of other publications. More about Kevin and links to his professional work can be found at www.kemibe.com.