The Binary Number System

 
 
 

Binary Number System (Base-2)
   The binary number system uses TWO values to represent numbers. The values are, 0 and 1
with 0 having the least value, and 1 having the greatest value. Columns are used in the same way as in the decimal system, in that the left most column is used to represent the greatest value.  As we have seen in the decimal system, the values in the set (0 and 1) repeat, in both the vertical and horizontal directions.
      0
      1
    10      Note: go to value lowest in set, carry to left
    11
  100      Note: go to value lowest in set, carry to left
  101
  110      Note: go to value lowest in set, carry to left
  111

binary number system simplified  explanation    In a computer, a binary variable capable of storing a binary value (0 or 1) is called a BIT.  In the decimal system, columns represented multiplication values of 10. That was because there were 10 values (0 - 9) in the set. In this binary system, there are only two values (0 - 1) in the set, so columns represent multiplication values of 2.
1101 becomes....
            1 * 20 = 1
            0 * 21 = 0
            1 * 22 = 4
            1 * 23 = 8
adding the results together gives 13 (in decimal)

Number Ranges in Binary Using A Specified Number Of Bits
How many different values can be represented by a specific number of bits ? 
            The Number of different values = 2n where n is the number of bits
                               e.g. 28 = 256 different values

The following examples show the basic rules For Binary Addition
                                  0 + 0  = 0
                                  0 + 1  = 1
                                  1 + 0  = 1
                                  1 + 1  = 0 and carry 1



Below is the example showing the rules For Binary Subtraction
                                  0 - 0  = 0
                                  0 - 1  = 1 and borrow 1
                                  1 - 0  = 1
                                  1 - 1  = 0

Binary Multiplication rules are illustrated below
                                  0 * 0  = 0
                                  0 * 1  = 0
                                  1 * 0  = 0
                                  1 * 1  = 1

Decimal to Binary Conversion
There are a number of ways to convert between decimal and binary. The most cpmmon is as follows: Divide the number by 2, then divide what's left by 2, and so on until there is nothing left (0). Write down the remainder (which is either 0 or 1) at each division stage. Once there are no more divisions, list the remainder values in reverse order. This is the binary equivalent.
   254 / 2 giving 127 with a remainder of 0
   127 / 2 giving 63 with a remainder of 1
     63 / 2 giving 31 with a remainder of 1
     31 / 2 giving 15 with a remainder of 1
     15 / 2 giving 7   with a remainder of 1
       7 / 2 giving 3   with a remainder of 1
       3 / 2 giving 1   with a remainder of 1
       1 / 2 giving 0   with a remainder of 1

thus the binary equivalent is 11111110

Representing Positive and negative Numbers in Binary
    When a number of bits is used to store values, the most significant bit  (the bit which has the greatest value, in the left most column) is used to store the sign (positive or negative) of the number. The remaining bits hold the actual value.   If the number is negative, the sign is 1, and for positive numbers, the sign is 0.
For example -7 is represented as
                                                 10000111

   Because of problems doing addition and subtraction, negative numbers are usually stored in a different format to positive numbers as shown below

Ones Complement

1's complement is a method of storing negative values. It simply inverts all 0's to 1's and all 1's to 0's.
                Original Number     Binary value         1's Complement value
                             7                00000111                  11111000

Twos Complement
2's complement is another method of storing negative values. It is obtained by adding 1 to the 1's complement value.

            Original Number    Binary value       1's Complement value            2's Complement value
                       7                 00000111                  11111000                            11111001

     Another way of generating a 2's complement number is to start at the least significant bit, and copy down all the 0's till the first 1 is reached. Copy down the first 1, then invert all the remaining bits.

To summarise Binary

 -    the numbers are cumbersome to write down
 -    long
 -    not very meaning to the average user
 -    a natural language easily understood  by computers
 

   
                   
     
                   
 

.      .

 
 

Copyright pc-control.co.uk 2008