The Math Forum

Ask Dr. Math - Questions and Answers from our Archives
Associated Topics || Dr. Math Home || Search Dr. Math

Binary Addition (2s Complement)

Date: 09/25/2001 at 19:22:53
From: Paul
Subject: Binary addition (2s complement)

Dear Dr. Math,

I was given a number in binary (10110111), and asked to convert first 
to decimal using 2s complement, then to BCD (binary coded decimal). My 
problem is in the understanding of how 2s complement works. Could you 
help me?


Date: 09/26/2001 at 03:43:51
From: Doctor Jeremiah
Subject: Re: Binary addition (2s complement)

Hi Paul,

2's complement was invented just so that binary numbers could be 
negative. If a binary number is positive, then 2's complement does 
nothing. So how do we know if a 2's complement binary number is 

Well, it depends on how many digits you are supposed to use. The 
reason this makes a difference is that if you are using 16-digit 
binary numbers, a number is negative if the 16th digit (the one on the 
left) is 1. So in this case your number (10110111) is actually 
0000000010110111 and does not have a 1 in the 16th digit.

However, if you are using 8-digit binary numbers, then your number 
(10110111) does have a 1 in the eighth digit (far left), and your 
number will be negative in this case.

Lets assume that the binary numbers are 8 digits long. That way your 
number is negative and far more interesting.

When you subtract x from y using the 2's complement rules, you 
basically just invert all the bits of x, add one to x, and then add 
that to y instead of subtracting.

For example:

    00000000        00000000          00000000
  - 00000001 ===> + 11111110+1 ===> + 11111111

So 00000000 - 00000001 (positive) = 11111111 (negative number)

To find the value, you convert it to a positive number and then put a 
minus sign in front of it.

So what about your number (10110111)?

Well if we do the same thing in reverse:

1. Take 10110111 and subtract 1 = 10110110
2. Take 10110110 and invert the bits = 01001001

This number (01001001) is the positive value that would have to be 
subtracted from 0 to give you 10110111.

So 00000000 - 01001001 (positive) = 10110111 (negative number)

   00000000        00000000          00000000
 - 01001001 ===> + 10110110+1 ===> + 10110111

It's relatively easy to convert 01001001 to decimal because there is 
nothing special to do: 0 (00000000) - 73 (01001001) = -73 (10110111).

- Doctor Jeremiah, The Math Forum   
Associated Topics:
High School Number Theory

Search the Dr. Math Library:

Find items containing (put spaces between keywords):
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

Math Forum Home || Math Library || Quick Reference || Math Forum Search

Ask Dr. MathTM
© 1994- The Math Forum at NCTM. All rights reserved.