Number System in C programming

Content:

  1.   Introduction and type of Number system 
  2.   Conversion between number system 
  3.   Arithmetic operations on number system
  4.   Signed and unsigned number system Software 
  5.   Computer Languages 
  6.   Computer Program

Introduction :

  •  A  number  system  is  a  writing  system  for expressing  numbers;  that  is,  a  mathematical notation for representing numbers of a given set, using  digits  or  other  symbols  in  a  consistent manner.
  • The  same  sequence  of  symbols  may  represent different numbers in different            numeral systems.

Type of Number system:

  •   This article throws light upon the four main types of number system. The types are:

  1.   Decimal System
  2.   Binary System
  3.   The Octal System
  4.  The Hexadecimal System.





1. Decimal system:

  • In decimal system the base (or radix) is 10, since any position can contain one of ten digits, refer (3) above. The system therefore has a carrying factor of 10 and each digit indicates a value which depends on the position it occupies, for example;
  •  In 6421 the digit 6 signifies 6 x 1000 
  • n 4621 the digit 6 signifies 6 x 100
  • n 4261 the digit 6 signifies 6 x 10
  • And in 4216 the digit 6 signifies 6 The decimal system uses ten digits to record the number. The ten digits are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 and any number (used) is based upon power of 10.
  •  For example 5281 is made up of: 
  • (5 x 103) + (2 x 102) + (8 x 101) + (1 x 100) 
  • = 5000 + 200 + 80 + 1 = 5281.

2. Binary System:

  • Whereas  decimal  system  uses  ten  digits  to  record  the number,  the  binary  system  uses  only  two  digits  (for recording the number) that is 0 and 1, and its base is 2 (whereas that of decimal system is 10). 
  •  Although  in  everyday  life,  people  generally  use  the decimal  number  system  for  counting,  it  is  more convenient to use the binary number system in a computer because electronic components are usually in one of two states, which can be used to represent 0 and 1, the two digits used in the binary system.
  • For  example: if  a  punched  paper  tape  is  used  in  the computer, a hole in a tape may allow electrical contact to be made (ON) and the absence of a hole in the tape does not allow electrical contact to be made (OFF). 
  • Therefore  a  hole  can  represent  1  and  no  hole  can represent  0.  Binary  system  is  more  compact  than  the decimal system of coding as the latter will need large size of the storage medium and relative complexity of the reading device.

Construction of binary numbers:

Binary numbers                 Equivalent decimal numbers
          
          2^3  2^2  2^1  2^0                                

                                    1                                      1
                            1      0                                      2
                            1      1                                      3
                    1      0      0                                      4
                    1      0      1                                      5
                    1      1      0                                      6
                    1      1      1                                      7
           1       0      0      0                                      8
           1       0      0      1                                      9



Conversion of a Decimal Number to Binary Equivalent:

  •  (a) Let the decimal number be 217.

                                                                         Remainder

 





  • Start binary number with last digit. Therefore the binary equivalent of 217 is 11011001.

  • (b) Convert .8125 into binary number.





  •     (c) Convert decimal number 217.8125 into binary number 

  •     From (a) and (b) above = Decimal No.=(217.8125)10
  •                                                 Binary No.=(11011001.1101)2



3. The Octal System:

  • The octal system (base 8) and hexadecimal system (base 16) are of importance because they can be used as a shorthand for binary numbers. This is because three binary digits can be represented by the numbers 0 to 7 i.e., the octal range, while four binary digits can be represented by the numbers 0 to 9 and A to F.








TABLE

Octal Binary Conversion


Octal                                                           Binary


                                   0                                                                  000
                                   1                                                                  001
                                   2                                                                  010
                                   3                                                                  011
                                   4                                                                  100
                                   5                                                                  101
                                   6                                                                  110
                                   7                                                                  111

















Post a Comment

0 Comments