Number System
Number System
Mathematics is the vital tool human has developed. It gives the human mind a capability to do the complex things by simple means. Similarly if I say that computer is based on mathematics then it should not be a surprise to you. First of all man invented zero, then the concept of decimal number system was invented.
It is for us to speculate that why we use only ten digits 0,1,2,3,4,5,6,7,8,9 to represent any number, whether it is a whole number or a fractional number. Probably the scientists at that time thought that this as most simple or we could say that we can always represent 10 digits with 10 fingers of our hands.
Otherwise we can have a number system that can be based on n digits where n can be any number of digits. Suppose I take a new no. System that will be called a single number system and contains only one digit with the symbol ‘1’.Then for representing two in this single number system we have to write 11 because we have only single digit to represent anything and for representing three and eight we have to write 111 and 11111111 respectively. Similarly if we have to add 111 and 111111, it will be 111111111. It is very similar to how a child starts learning the number arithmetic.
So similarly we can have any number system based on n digits that will be called n-digit number system. The number of digits particular number system uses is also called the base or radix of that number system.
Binary number system: The computer recognizes binary number system that consists of two digits i.e. 0,1. The reason for this is that we have two voltage levels in which one voltage level represents zero and another one. For storage and retrieval purposes also the hardware that is used in computer is such that it can handle only two values. So Binary number system is best suited for the computer operations.
For understanding the various processes being performed by the computer we need to understand the binary number system. The end user who is using an application of computer science does not need to know the binary number system because he can write in the usual symbols being used, but these symbols will be converted into binary number system by the computer internally. The computer will do the processing and will again represent them to the normal symbols as understood by the user.
The base or radix of the binary number system is two because it uses only two digits namely 0,1.
Storage Units:
In computer memory the smallest unit of memory is called a bit. It can store either a zero or one. Eight bits comprise to form a byte.
Conversion between different prevalent number systems
Binary Number | Octal Number | Decimal Number | Hexadecimal Number |
0000 | 0 | 0 | 0 |
0001 | 1 | 1 | 1 |
0010 | 2 | 2 | 2 |
0011 | 3 | 3 | 3 |
0100 | 4 | 4 | 4 |
0101 | 5 | 5 | 5 |
0110 | 6 | 6 | 6 |
0111 | 7 | 7 | 7 |
1000 | 10 | 8 | 8 |
1001 | 11 | 9 | 9 |
1010 | 12 | 10 | A |
1011 | 13 | 11 | B |
1100 | 14 | 12 | C |
1101 | 15 | 13 | D |
1110 | 16 | 14 | E |
1111 | 17 | 15 | F |
* Octal numbers system consists of the eight symbols 0,1,2,3,4,5,6,7.
** Hexadecimal Number system consists of the sixteen symbols 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
While using the decimal number system we describe the number 3578 as the combination of 8 at the unit place, 7 at the ten’s place, 5 at the hundred’s place and 3 at thousand’s place. Basically we are increasing the exponential value of 10 by one for every next position i.e.
100 * 8 for unit place + 101 * 7 for ten’s place + 102 * 5 for hundred place + 103 * 3 for thousand’s place
Which becomes 8+70+500+3000 = 3578
The rule to convert any number from other number system into a decimal number system is :
Sum of Positional value from left to right as number * (base of the no. System)position starting from zero
So in the similar manner we take a binary number 101101.
The base of the binary number is two, So apply the above rule 7 we get
20 * 1 + 21 * 0 + 22 * 1 + 23 * 1 + 24 * 0 + 25*1 = 1+0+4+8+0+32 = 45
So in decimal number system the value of 101101 is 45 . we write it like (101101)2 = (45)10
Take the Binary number with fractional part 1011.10111
Only change is that after the decimal point we do it from right to left.
It will be converted as
(20 * 1 + 21 * 1 + 22 * 0 + 23 * 1 ) +( 2 -1 * 1 + 2 –2 * 0 + 2-3 * 1+ 2-4 * 1 + 2-5 * 1) = (1+2+0+8) + (0.5 + 0.125 + 0.0625 + 0.03125) = 11.71875
Therefore (1011.10111)2 = (11.71875)10
Now let us take an Octal number 652. The base of the number system is eight. By applying the above rule we get
80 * 2 + 81 * 5 + 82 * 6 = 2+40+384 = 426
So in decimal number system the value of octal number 652 is 426. We write it like (652)8 = (426)10
Take a octal number with fractional part 77.42
This will be converted as
(80 * 7 + 81 * 7 ) +( 8 -1 * 4 + 8 –2 * 2 ) = 7+56+0.5+0.03125 = 63.53125
Therefore (77.42)8 = (63.53125)10
Similarly to convert a hexadecimal number into a binary number we use the above formula.
Take a Hexadecimal Number 1AF73. The base of the number system is 16.
As given in above table the Hexadecimal A is equivalent to decimal 10, B is same as 11, C is same as 12, D is same as 13, E is same as 14 and F is same as 15. By applying the above rule we get
160 * 3 + 161 * 7 + 162 * F + 163 * A + 164 * 1 = 3 + 112 + 3840 + 40960 + 65536 =110451 So in decimal number system the value of Hexadecimal number 1AF73 is 110451
We write it as (1AF73)16 = (110451)10
Take an Hexadecimal number with fractional part BC1.DE
This will be converted as
(160 * 1 + 161 * 12 + 162 * 11) +( 16 -1 * 13 + 16 –2 * 14) = 1+192+ 2816+0.8125+0.0546875 = 3009.8671875
therefore (BC1.DE)16 = (3009.8671875)10
Coversion of Decimal number system to another number system
The rule for conversion is
Base of the number system | Decimal number |
quotient | remainder |
So let us convert a decimal number 95 to binary number. Here the base of the binary number is 2 and the decimal number is 95. By following the above rule the quotient of 95 when we divide by 2 is 47 and remainder is 1. we proceed doing the similar operation. Divide the 47 by 2, the quotient is 23 and remainder is 1, again divide 23 by 2, the quotient is 11 and remainder is 1. We go on doing like this until the number becomes less then 2.
2 | 95 | |
2 | 47 | 1 |
2 | 23 | 1 |
2 | 11 | 1 |
2 | 5 | 1 |
2 | 2 | 1 |
1 | 0 |
Now we write the remainder in the direction of the arrows given and get the binary number i.e. 1011111.
Therefore (95)10 = (1011111)2
If we have decimal number with fractional part then rule is
Base of the number system | Decimal number |
Fractional part | Integral part after multiplication |
Let us convert decimal 0.71875 to binary equivalent
2 | 0.71875 | 2*0.71875 = 1.4375 Fraction = 0.4375 Integeral = 1 |
2 | 0.4375 | 1 2*0.4375 = 0.875 Fraction = 0.875 Integeral = 0 |
2 | 0.875 | 0 2*0.875 = 1.75 Fraction = 1.75 Integeral = 1 |
2 | 0.75 | 1 2*0.75 = 1.5 Fraction = 0.5 Integeral = 1 |
2 | 0.5 | 1 2*0.5 = 1.0 Fraction = 0.0 Integeral = 1 |
0.0 | 1 |
Therefore (0.71875)10 = (0.10111)2
Similarly to convert Decimal number 268 to an octal number
The base of the number is eight and the decimal number is 268 . No the division is done by eight and we proceed until the number is less than 8.
8 | 269 | |
8 | 33 | 5 |
4 | 1 |
Therefore (268)10 = (415)8
For converting a decimal number with fractional part 199.0625 in to an octal number
Here the base of the number is eight. Both the Integral part (199) and the fractional part (0.0625) has to be dealt separately. By applying the corresponding formula.
8 | 199 | 0.0625 | .0625*8=0.5 | |
8 | 24 | 7 | 0.5 | 0 0.5*8 = 4.0 |
3 | 0 | 0.0 | 4 |
We get (199.0625)10 = (307.04)8
To convert a decimal number 1579 to its hexadecimal equivalent
Here the base of the number is 16 and the decimal number is 1579.
16 | 1579 | |
16 | 98 | 11 |
6 | 2 |
Before writing the hexadecimal equivalent we have to convert the remainder 10,11,12,13,14,15,to A,,B,C,D,E,F respectively, if present in the table. Here we change 11 to A.
16 | 1579 | |
16 | 98 | A |
6 | 2 |
Therefore (1579)10 = (62A)16
For Converting a Decimal Number with fractional part 99.99 to Hexadecimal number
16 | 99 | 0.99 | 0.99 * 16 = 15.84 |
6 | 3 | 0.84 | 15 0.84 * 16 = 13.44 |
0.44 | 13 0.44 * 16 = 7.04 | ||
0.04 | 7 0.04 * 16 = 0.64 | ||
0.64 | 0 0.64 * 16 = 10.24 | ||
0.24 | 10 0.24 * 16 = 3.84 |
The process can continue further, but it is up to us that up to what decimal place we want to calculate, So we restrict ourselves to the 6 decimal places. Now we have to convert 10,11,12,13,14,15,16 to A,B,C,D,E,F wherever required
16 | 99 | 0.99 | 0.99 * 16 = 15.84 |
6 | 3 | 0.84 | F 0.84 * 16 = 13.44 |
0.44 | D 0.44 * 16 = 7.04 | ||
0.04 | 7 0.04 * 16 = 0.64 | ||
0.64 | 0 0.64 * 16 = 10.24 | ||
0.24 | A 0.24 * 16 = 3.84 |
Therefore (99.99)10 = (63.FD70A3)16 Approx.
In the above fashion we can convert any number from one number System to Decimal number System and Vice Versa.
Now Let us see the conversion from Binary to Octal and Binary to Decimal Number System.
We know that octal number System has eight symbols. One binary bit can represent two numbers 0,1.Two binary bits can represent four numbers 00,01,10,11. three binary bits can represent 000, 001, 010, 011, 100, 101, 110, 111 . Similarly four binary bits can represent 16 numbers. It increases by the power of 2. So eight binary bits can represent 28 Numbers.
The clue is taken from the above discussion that for converting a Binary to Octal and Octal to Binary we need three Binary bits to recognize one octal digit.
For conversion of 1100111000010 to an octal number we make the group of three starting from the left.
1100111000010 as 1 100 111 000 010
Now from the above table corresponding octal values are taken
1 4 7 0 2 Therefore (1100111000010)2 = ( 14702)8
For converting 11011.01101 to an octal number. The direction we have to make the groups is different on both sides of the decimal . as has been shown with the arrow marks.
11011 . 01101 011 011 . 011 010 = 3 3 . 3 2 Therefore (11011.01101)2 = (33.32)8
Convert octal number 567 to Binary number . we have to convert every octal digit to equivalent three binary numbers
5 6 7 = 101 110 111 Therefore (567)8 = ( 101110111)2
for octal number with fractional part 42.01 we follow the same rule
4 2 . 0 1 100 010 . 000 001
therefore (42.01)8 = (100010.000001)2
For converting Binary to Hexadecimal numbers group of four bits is taken instead of three.
For converting 101111101 to hexadecimal
101111101 1 0111 1101 = 1 7 D Therefore (101111101) 2 = (17D)16
for converting 10011000.00101 to hexadecimal
1001 1000 . 0010 1000 = 98.28
(10011000.00101)2 = (98.28)16
Similarly to convert hexadecimal 37C to binary number
3 7 C = 0011 0111 1100 therefore (37C)16 = (1101111100)2
To convert A2.7F into binary number
A 2 . 7 F = 1010 0010 . 0111 1111 therefore (A2.7F)16 = (10100010.01111111)2
In the last we are left with the conversion from Hexadecimal to Octal and Vice Versa
We convert hexadecimal 10.CD to Octal number
It is done with two steps
convert the number into Binary Number and then convert that binary to octal number
1 0 . C D = 0001 0000 . 1100 1101 So (10.CD)16 = (10000.11001101)2
Now to convert this in octal we make group of three
010 000 . 110 011 010 20.62
(10000.11001101)2 = (20.62)8
Therefore (10.CD)16 = (20.62)8
For converting an Octal 136.204 to Hexadecimal number
First convert 136.204 to Binary
1 3 6 . 2 0 4 001 011 110 . 010 000 100
(136.204)8 = ( 1011110.010000100)2
Now we make the units of four to convert this into hexadecimal
0101 1110 . 0100 0010 = 5E.42
( 1011110.010000100)2 = (5E.42)16
Therefore (136.204)8 = (5E.42)16
Binary Mathematics
Binary addition Rules are similar as we add two decimal numbers
Decimal adition Binary Addition
234 1010
+ 940 1100
———— ———-
1174 10110
Carry Carry
So in binary 0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 10 ( Because in binary 2 is represented by 10)
As above in decimal addition we say that 2 + 9 is 1 with carry 1, similarly in binary we say 1 + 1 is 0 with carry 1.
Subtraction
We take the following example to understand the subtraction process.
Borrow Borrow
736 1001
-293 0101
———– ————
443 0100
As above we subtract 9 from 3 , we take borrow from 7 which reduces to 6 and we perform subtraction of 9 from 13. similarly when we subtract 1 from 0 we take a borrow from the next available 1 which reduces to 0 and we perform subtraction of 1 from 10 (which is 2 in decimal).
1 – 0 = 1
0 – 0 = 0
1 – 1 = 0
0 – 1 = 1 with borrow 1
Actually the subtraction is performed using the addition circuit in the computer. For understanding how this is possible we need to understand a few terms
N’s complement
If we subtract each digit of any number from N , then the result is called the N’s complement of the number.
Let us say 7’s complement of 3456
So 7’s complement will be
7777
3456
———-
4321
4321 is the 7’s complement of 3456.
Similarly
1’s complement of 1011001 will be 1111111
1011001
————
0100110
100110 is 1’s complement we can simply say that converting 1 to 0 and 0 to 1 will give us the 1’s complement.
In binary number system we don’t have the symbol 2 , for getting 2’s complement in binary number system, we add 1 to the 1’s complement of the number.
So for above 1’s complement 2’s complement will be 0100110 + 1 = 0100111
Why we are discussing this, because it has an important application in subtraction of the numbers
Let us again look at the subtraction we had performed
We will do this using addition , we take the two’s complement of the binary number to be subtracted
i.e 0101 first we take 1’s complement by changing 1 to 0 and 0 to 1.
so it becomes 1010 . For 2’s complement we add 1. It becomes 1011
Normal subtraction Subtraction using addtion
1001 1001
0101 1011
——- ——–
0100 10100
carry If we drop the carry result is same as normal subtraction.
Rule : Subtraction is equivalent to performing the addition with 2’s complement of the binary number with last carry dropped, if present.
Another corollary of this rule is that negative numbers in computers are represented by the 2’s complement of the number. In computer we have only 0 and 1. So positive and negative signs are also represented by 0 and 1 respectively.
If we have 8 bits to represent a number then 7 will be represented by
00000111
for representing –7 it will be 00000111
11111000 1’s complement
1 add 1
11111001 2’s complement
So –7 will be represented by 11111001 in computer
For cross checking it let us perform the subtraction using addition of 7 and -7 which should be zero.
0 0 0 0 0 1 1 1
1 1 1 1 1 0 0 1
——————–
1 0 0 0 0 0 0 0 0
We drop the carry according to the rule and the result is zero.