You are on page 1of 2

Arithmetics of non-decimal numbers

Edit
Just as rules exist for arithmetic operations on decimal numbers, there are a
number of techniques for evaluating various operations in non-decimal bases.

Several systems have been designed to represent negative numbers in binary. The
most commonly used is called two's complement. This system is popular because
numbers using this representation are easy to negate, and arithmetic operations can
be performed on both positive and negative numbers in the same manner.

In two's complement, binary values whose most significant bit (MSB) is 0 are
positive, whereas those whose MSB is 1 are negative. To negate a two's complement
binary number, invert all of the bits and add one. For example, 00010110 (22 in
decimal) becomes 11101010 (-22 in decimal).

There are two common methods of calculating the two's complement of a binary
number. The first is to first use one's complement, which is the simple inversion
of each bit (1 becomes 0; 0 becomes 1). So the given binary representation of
decimal 22, converted to one's complement is 11101001. To obtain the two's
complement from the one's complement, just add 1. This yields 11101010 (-22
decimal). The mechanics of addition will become clearer as you progress. The other
method is a shortcut to using one's complement and adding one; it takes advantage
of the fact that adding 1 forces you to carry that bit during the addition, so we
save ourselves some work ahead of time: beginning with the least significant bit
(LSB), keep all of the 0-bits and the least significant 1-bit (10 in our example);
then invert all of the bits more significant than that least significant 1-bit
(111010); finally, the end result is 11101010 (-22 decimal).

Addition
Edit
To perform addition in any number system, begin with the LSB. Combine the two LSB's
but if you exceed the base, you must carry a one to the next position. Any
difference between the total combination computed and the base is to be left in
that position. Here is an example in decimal: 456 + 789:

111
456
+789
------
1245
In the first place (places are numbered beginning with the least significant bit,
a.k.a. right-most), we have 6 + 9, which yields 15. Because we are in decimal, we
can only use {0-9}, so after 9, we need to carry one to the next place. 15 = 10 +
5, so 5 remains in the first place, and we carry the 10, but when we carry 10 to
the next place, it is represented as 1.
In the second place, we have 3 terms to combine: 1 + 5 + 8, yielding 14. Again, 14
= 10 + 4, so we leave 4 as the result in the second place and carry the 10 as a 1
to the third place.
In the third place, we have 1 + 4 + 7 = 12. We see that 12 = 10 + 2, so we leave 2
as the result in the third place and carry the 10 as a 1 to the fourth place.
In the fourth place, which did not exist at the start of the problem, we have 1.
This is the resultant value for the fourth place since there are no other terms
with which to combine it.
And there you have it! In binary, it is slightly easier, because you will notice
that after 1, we have already reached the base, so just zero the current position,
and carry that 1 to the next position. It should feel like flipping bits, which it
is!

In Binary Addition, We have to use following truth Table


A B A+B
0 0 00
0 1 01
1 0 01
1 1 10
The most significant bit in A+B is carry and is taken to next bit in addition.Here
is an example: 1111 + 0101;
1111
1111 15
0101 5
+-----
10100 20
Subtraction
Edit
Similar to Addition specified above we can perform binary Subtraction using truth
table below
A B A-B
0 0 00
0 1 10(carry is -1 which is absurd in binary representation)
1 0 01
1 1 0
Multiplication
Edit
When doing multiplication with binary numbers the following truth table is used.
The truth table for addition is also needed.

A B A*B
0 0 0
0 1 0
1 0 0
1 1 1
Example multiplication:

1011 11
101 5
*-----
1011
0000
1011
+------
110111 55

You might also like