Saturday, September 21, 2013

Binary number operations

Binary Number Operations


Addition

0 + 0 → 0
0 + 1 → 1
1 + 0 → 1
1 + 1 → 0, carry 1

For e.g

  1 1 1 1 1    (carried digits)
    0 1 1 0 1
+   1 0 1 1 1
-------------
= 1 0 0 1 0 0 = 36

Subtraction

0 − 0 → 0
0 − 1 → 1, borrow 1
1 − 0 → 1
1 − 1 → 0

Subtracting a “1" digit from a "0" digit produces the digit "1", while
1 will have to be subtracted from the next column. This is known as
borrowing.

    *   * * *   (starred columns are borrowed from)
  1 1 0 1 1 1 0
−     1 0 1 1 1
----------------
= 1 0 1 0 1 1 1

Multiplication

           1 0 1 1   (A)
         × 1 0 1 0   (B)
         ---------
           0 0 0 0   ← Corresponds to the rightmost 'zero' in B
   +     1 0 1 1     ← Corresponds to the next 'one' in B
   +   0 0 0 0
   + 1 0 1 1
   ---------------
   = 1 1 0 1 1 1 0

Binary Multiplication for binary point
                 1 0 1 . 1 0 1       A (5.625 in decimal)
                 × 1 1 0 . 0 1       B (6.25  in decimal)
             -------------------
                   1 0 1 1 0 1    ← Corresponds to a 'one' in B
     +           0 0 0 0 0 0      ← Corresponds to a 'zero' in B
     +         0 0 0 0 0 0
     +       1 0 1 1 0 1
     +     1 0 1 1 0 1
     ---------------------------
     = 1 0 0 0 1 1 . 0 0 1 0 1  (35.15625 in decimal)


Negative Binary number

How can we represent a negative number? We cannot use a ‘-‘ sign because all we can store in the computer is zeros and ones.

There are three methods

  • Signed Magnitude
  • 1’s Complement
  • 2’s complement

No comments:

Post a Comment