View Full Version : Maths question


Adam
05-30-02, 02:56 AM
Could someone please give me some examples of addition and subtraction in binary, using ones complement and twos complement numbers? Thanks.

James R
05-30-02, 06:01 AM
example: 4 bit, twos complement numbers:

The number 3 in this system is: 0011

The ones complement of that number is 1100
The two's complement is 1101

So, the number -3 is represented by 1101.

Note that in this system, the representable range of numbers is from -8 to +7.

The number 1 is 0001 in this system.

Suppose I want to work out the answer to (1-3).

First, I take the twos complement of 3, which is 1101.
Then add 1 to -3:

0001 + 1101 = 1110

This answer is a negative number since the first bit is 1.

The ones complement of the answer is 0001.
The twos complement is 0010, which is the negative of the answer, so the answer is -2.

Adam
05-30-02, 11:41 AM
Kick arse, thanks.