General Computer Science (Chapter 1 ) : Number System


For any type of consultation, query or doubt. You may contact to the following: (+91) 9804 436 193 debabrataguha20@gmail.com 
You will get all the exercise in the Facebook group  https://www.facebook.com/groups/331231161093613/ 


First thing I want to tell you that this chapter will help you to understand the core logic of computer science by heart. But if you are here only to score the marks, then your academic book will be best. But who want both, I will suggest them to understand the logic first , then go through your academic book.



From the ancient age , when people could not talk , they wished to communicate between themselves by someway. Either by making some sounds or by drawing something. Just imagine what will happen if we stop talking suddenly. So finally when human invented some scripts in various corners of the world, they felt necessity to invent some numbers as well. Currently there are few thousands of languages exist in the world. Many of them are already lost. So imagine, our numbers also look different in different languages.


        

 In Chinese                                         






In hindi   









In Arabic












You can also create your own number system by assigning each digit to some symbols or drawings or icons. In my childhood days I created my own number system to store my password, girlfriends phone numbers etc. 😊 It was somewhat like below:














…….. and so on ….



So how many symbols you have to imagine to create your number system. Most of the time, I got the answer as ten. Meaning I have to assign ten different icons for the digits from Zero to Nine.
So, 10 will be represented as






11 will be represented as  




12 will be represented as 

 






We do the same in most of the languages. The common factor is that in most of the languages we have assigned 10 different icons for the digits from zero to nine.

Like in English we have defined only 10 different icons for the digits zero to nine like below:









So whenever I will require the number next to nine. I will reuse the icons for one and zero and make it “10” . So if you can think something beyond your book, then you will feel that we can create all the millions and billions of numbers using these ten icons only. So I can also create the million and billions of numbers using my number system as well, or in hindi, arabic number systems aswell.

But the common thing is we just need to invent ten different icons. That is why these number systems are called “decimal number system” or “number system having base 10”.




Number systems with more than 10 icons :

Not all human number systems use ten icons only. If you can remember roman numbers. It is a bit different like below:

In Chinese and Japanese number systems also, you will get more than ten icons.




Topic 1: Number systems used by computer

I am sure that everyone of you know that computer only understands zero and one. So my question then to you is why only zero and one?? If computer is able to understand 0 and 1 , then why not 2,3,4,5 .. 9 ? Actually computer does not understand 0 and 1 aswell.

It is only OFF and ON. OFF means “no current/electricity” and ON means “current/electricity is there”.

So, 1001001 means ONOFFOFFONOFFOFFON

This number system is called as “Binary number systems” or “ Number system with base 2”


In decimal, to express ten , we use “1” and “0”. Because we do not have any specific icon for “ten”. Same here, we do not have any specific icon for “two” , so we use “1” and “0” to represent 2..

In both the number systems “Decimal” and “Binary”, If we have already completed all single digit characters, then we increase the count of digits to define the new numbers. Please follow the below chart:

Numbers Decimal Binary
Zero
0
0
One
1
1
Two
2
10
Three
3
11
Four
4
100
Five
5
101
Six
6
110
Seven
7
111
Eight
8
1000
Nine
9
1001
Ten
10
1010
Eleven
11
1011
Twelve
12
1100
Thirteen
13
1101
Fourteen
14
1110
Fifteen
15
1111
Sixteen
16
10000
Seventeen
17
10001
Eighteen
18
10010
Nineteen
19
10011
Twenty
20
10100
Twenty one
21
10101
…. ….
Ninetynine
99
1100011
Hundred
100
1100100
Hundred and one
101
1100101

Look carefully, whenever we are shortage with the digits, we are increasing the digit count. In binary “11” , we have used all the 2 digit combination. So started using 3rd digit and made it “100”.

Similarly in case of Decimal “99” , we have used all the 2 digit combinations, so we started using a 3 digit number from “100”.



So it is really tough or impossible to remember those binary numbers. So there is a mathematical way to convert a decimal number into binary.


Topic 1.1: Mathematical way to convert Decimal to Binary  :

Process to convert decimal to binary is very simple.

Step 1: Need to divide the decimal number by 2
Step 2: Store the remainders
Step 3: repeat these steps until the number becomes zero
Step 4: Collect the remainders in reverse order.


This mathematical process will be clear if we take an example:

Example 1.1:

Here we are converting decimal 19 to binary













I am sure that you are stronger than me in mathematics. For the last time I have used mathematics in my college life. Here you just need to divide a number by 2 everytime and collect the remainders. Most important is to collect the remainders in the reverse order.

So the answer is, (19)10=(10011)2


Example 1.2:

Follow another example of conversion of decimal 98 to binary.

Or, (98)10 = (?)2













So as a result, (98)10=(1100010)2




Some logical people who loves to think, they used to say that we are dividing the decimal number by 2 , only because of we need 1 and 0. Means if you divide a number by 2 , then you will always get remainders as 1 and 0. That is the reason for choosing 2 as divisor in all the mathematics related to “binary”.



Topic 2: Octal Number system

In Octal number system, people only use 8 numbers (zero to seven, 0 -7).

Numbers Decimal Binary Octal
Zero
0
0
0
One
1
1
1
Two
2
10
2
Three
3
11
3
Four
4
100
4
Five
5
101
5
Six
6
110
6
Seven
7
111
7
Eight
8
1000
10
Nine
9
1001
11
Ten
10
1010
12
Eleven
11
1011
13
Twelve
12
1100
14
Thirteen
13
1101
15
Fourteen
14
1110
16
Fifteen
15
1111
17
Sixteen
16
10000
20
Seventeen
17
10001
21
Eighteen
18
10010
22
Nineteen
19
10011
23
Twenty
20
10100
24
Twenty one
21
10101
25
…. …. ….
Ninetynine
99
1100011
143
Hundred
100
1100100
144
Hundred and one
101
1100101
145

Now again it is not possible to remember all those Octal number, so we need to calculate the octal number in a similar way like previous. So if you are clever enough , you can now guess the number by which I will divide the decimal numbers. Yes.. It is 8 , because if we divide any number with 8 , then only we will get remainders 0 to 7. So let us choose the same numbers again as example

Example 2.1:



     






That means (19)10 = (23)8


Example 2.2:











that means (98)10 = (142)8







Topic 3: Hexadecimal Number systems

In Hexa-Decimal number system, base is 16. It is 0-9, and then for the rest of the numbers they use alphabets  from A-E.

Numbers Decimal Binary Octal HexaDecimal
Zero
0
0
0
0
One
1
1
1
1
Two
2
10
2
2
Three
3
11
3
3
Four
4
100
4
4
Five
5
101
5
5
Six
6
110
6
6
Seven
7
111
7
7
Eight
8
1000
10
8
Nine
9
1001
11
9
Ten
10
1010
12
A
Eleven
11
1011
13
B
Twelve
12
1100
14
C
Thirteen
13
1101
15
D
Fourteen
14
1110
16
E
Fifteen
15
1111
17
F
Sixteen
16
10000
20
10
Seventeen
17
10001
21
11
Eighteen
18
10010
22
12
Nineteen
19
10011
23
13
Twenty
20
10100
24
14
Twenty one
21
10101
25
15
…. …. …. ….
Ninetynine
99
1100011
143
63
Hundred
100
1100100
144
64
Hundred and one
101
1100101
145
65
Hundred and Two
102
1100110
146
66
Hundred and three
103
1100111
147
67
Hundred and four
104
1101000
150
68
Hundred and five
105
1101001
151
69
Hundred and six
106
1101010
152
6A
Hundred and seven
107
1101011
153
6B
Hundred and eight
108
1101100
154
6C
Hundred and nine
109
1101101
155
6D
Hundred and ten
110
1101110
156
6E
Hundred and eleven
111
1101111
157
6F
Hundred and twelve
112
1110000
160
70

Let’s take some examples


Example 3.1:













means (19)10 = (13)16


Example 3.2:










 means (98)10=(62)16


Example 3.3:









If you check the list above,

10 is represented by A
11 is represented by B
12 by C
13 by D
14 by E
15 by F

So (110)10=(6E)16



Topic 4: Return back to Decimal

We can consider our decimal number as the best one and as the top mountain like the below picture.



So we have already converted Decimal number to other number systems.. as we can see in the picture above , till now, we always went down. So now what will happen if we want to go up. Means now we want to convert a Hexa number into Decimal or an Octal number into Decimal or a Binary number into Decimal. So now if we want to go up, we need to use multiplication.


First we can start from Binary to Decimal.

Example 4.1:

(10011)2=(?)10

The process of conversion is like below:

1  0  0  1  1
            x     x    x    x    x
            24   23   22  21  20
______________________
=        16 +0 +0 +2 +1
=          19

So what we have done here? As “Binary” is involved , we are using “2” everywhere.

So for the digit in 1st decimal place we use 2 to the power 0, that is 1 for multiplication
So for the digit in 2nd decimal place we use 2 to the power 1, that is 2 for multiplication
So for the digit in 3rd decimal place we use 2 to the power 2, that is 4 for multiplication
So for the digit in 4th decimal place we use 2 to the power 3, that is 8 for multiplication
So for the digit in 5th decimal place we use 2 to the power 4, that is 16 for multiplication

So after multiplication if we add all the results, we will get answer as 19.



Example 4.2:

Let’s take another example:

(1100010)2=(?)10

The process of conversion is like below:

1  1  0  0  0  1  0
            x    x    x    x    x    x     x
            26  25  24   23  22   21   20
______________________
=      64+32+0 +0 +0 +2 +0
=       98

So what we have done here? As “Binary” is involved , we are using 2 everywhere.

So for the digit in 1st decimal place we use 2 to the power 0, that is 1 for multiplication
So for the digit in 2nd decimal place we use 2 to the power 1, that is 2 for multiplication
So for the digit in 3rd decimal place we use 2 to the power 2, that is 4 for multiplication
So for the digit in 4th decimal place we use 2 to the power 3, that is 8 for multiplication
So for the digit in 5th decimal place we use 2 to the power 4, that is 16 for multiplication
So for the digit in 6th decimal place we use 2 to the power 5, that is 32 for multiplication
So for the digit in 7th decimal place we use 2 to the power 6, that is 64 for multiplication

So after multiplication if we add all the results, we will get answer as 98.





Topic 5: Octal to Decimal

So now we will convert from Octal to Decimal. So here the base will be 8 as expected. We will use 8 everywhere. Rest of the logics are same.

Example 5.1:

(23)8=(?)10

The process of conversion is like below:

2  3
            x     x
           81    80
______________________
=       16+3
=         19

So for the digit in 1st decimal place we use 8 to the power 0, that is 1 for multiplication
So for the digit in 2nd decimal place we use 8 to the power 1, that is 8 for multiplication


So after multiplication if we add all the results, we will get answer as 19.





Example 5.2:

Let’s take another example:

(142)8=(?)10

The process of conversion is like below:

1  4  2
            x     x    x
           82   81   80
______________________
=       64+32+2
=         98

So what we have done here? As “Octal” is involved , we are using 8 everywhere.

So for the digit in 1st decimal place we use 8 to the power 0, that is 1 for multiplication
So for the digit in 2nd decimal place we use 8 to the power 1, that is 8 for multiplication
So for the digit in 3rd decimal place we use 8 to the power 2, that is 64 for multiplication

So after multiplication if we add all the results, we will get answer as 98.




Topic 6: HexaDecimal to Decimal:

So now we will convert from Hexadecimal to Decimal. So here the base will be 16 as expected. We will use 16 everywhere.


Example 6.1:

(6E)16=(?)10

The process of conversion is like below:

6  E
                          (14)
            x     x
          161  160
______________________
=      96+14
=       110

So for the digit in 1st decimal place we use 16 to the power 0, that is 1 for multiplication
So for the digit in 2nd decimal place we use 16 to the power 1, that is 16 for multiplication

So after multiplication if we add all the results, we will get answer as 110.




Example 6.2:

Let’s take another example:

(AFD)16=(?)10

The process of conversion is like below:

A  F  D
                    (10)  (15)  (13)
             x     x     x
           162 161 160
______________________
=   2560+240+13
=    2813

So what we have done here? As “Hexa-Decimal” is involved , we are using 16 everywhere.

So for the digit in 1st decimal place we use 16 to the power 0, that is 1 for multiplication
So for the digit in 2nd decimal place we use 16 to the power 1, that is 16 for multiplication
So for the digit in 3rd decimal place we use 16 to the power 2, that is 256 for multiplication

So after multiplication if we add all the results, we will get answer as 2813.





Topic 7: Moving from one Number system to another

Suppose I want to convert a binary number into HexaDecimal. How to do that?

The answer will be 2 stepped.
Step 1: Convert from hexadecimal to Decimal
Step 2: Convert from Decimal to Octal.


Example 7.1:

(100100)2=(?)16

1x25 + 0x24 + 0x23 + 1x22 + 0x21 + 0x20 = (36)10

Now need to convert decimal 36 to hexadecimal









So the answer is
(100100)2=(24)16



So by this way, we can covert from any number system to another.



Topic 8: Relation Among HexaDecimal, Octal & Binary

But there is a hidden relation between Octal and HexaDecimal. Binary is the bridge between them.

Short cut can be achieved by below 2 relations:


Relation 1: Each HEX digit can be directly converted into 4 digit binary numbers
Relation 2: Each Octal digit can be directly converted into 3 digit binary numbers


You can refer to the below list as we used before:

Decimal Binary Octal HexaDecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000
8
9 1001
9
10 1010
A
11 1011
B
12 1100
C
13 1101
D
14 1110
E
15 1111
F

But we have to be strict on the binary digit count. Octal should be a 3 digit binary number and Hexadecimal should be a 4 digit binary. Better to use the following table after doing a little modification.

Binary Octal Octal->Binary HexaDecimal HexaDecimal-->Binary
0
0
000
0
0000
1
1
001
1
0001
10
2
010
2
0010
11
3
011
3
0011
100
4
100
4
0100
101
5
101
5
0101
110
6
110
6
0110
111
7
111
7
0111
1000


8
1000
1001


9
1001
1010


A
1010
1011


B
1011
1100


C
1100
1101


D
1101
1110


E
1110
1111


F
1111





Example 8.1:

(AB)16=(?)2

As per the above chart , A means 1010
                                         B means 1011
So (AB)16=(10101011)2



Example 8.2:

(31)16=(?)2

As per the above chart , 3 means 0011
                                         1 means 0001

So (31)16=(00110001)2



Example 8.3:

(10010)2=(?)16

As destination is Hexadecimal, Make the count of binary numbers to a multiple of 4 by adding initial zeroes.

00010010
= 0001 0010
= 1 2

So, (10010)2=(12)16





Example 8.4:

(10010)2=(?)8

As destination is Octal, Make the count of binary numbers to a multiple of 3 by adding initial zeroes.

010010
= 010 010
= 2 2

So, (10010)2=(22)8

  



Example 8.5:

(32)8=(?)2
3 means 011
2 means 010

So, (32)8=(11010)2



Example 8.6:

(70)8=(?)2
7 means 111
0 means 000

So, (70)8=(111000)2



Example 8.7:

Now if we want to directly conversion between Octal and Hexadecimal.
(6E)16=(?)8

Step1:

Convert each HexaDigit to a 4 digit binary number

  6      E
0110 1110

Step 2:


Extract 3 digit Octal codes. You can add initial zeroes to make the number 3 digit.









So (6E)16 = (156)8





Example 8.8:

(AB)16=(?)8

A      B
1010  1011

=10101011
= 010 101 011
= 253

So, (AB)16=(253)8




Example 8.9:

(217)8=(?)16
2    1   7
010 001 111                after converting each Octal digit to 3 digit binary number
=010001111                after merging them
=0001 0000 1111        after separating it out by 4 digits
= (1 0 F )16                                After converting each 4 digits to HexaDecimal

So, (217)8=(10F)16



Example 8.10:

A      B
1010  1011

=10101011
= 010 101 011
= 253

So, (AB)16=(253)8









Topic 9: Fractional value conversation

Let’s start with an example,

Example 9.1:

Now we are able to convert (14)10 to binary easily. But what about 14.325? If I ask to convert 14.325 into binary. The process is like below.

Step 1:
            First we will convert 14 from decimal into binary as per previous process  
          









(14)10 = (1110)2


Step 2:
            Now to handle the point value. We will multiply the point value (that is .325) with 2 always. So each time we will take the whole number part (marked in red). Means the value in the left of decimal point. Check the same below:

            .325  X 2  =  0.750       0
            .750  X 2  =  1.50         1
            .50    X 2  =  1.0            1

If it becomes zero, that means it is done.

So all together, 14.325 = 1110.011



Example 9.2:

But sometime it does not reach to zero. Like if I want to convert 14.6 into Binary?

            .6  X 2  =  1.2               1
            .2  X 2  =  0.4               0
            .4  X 2  =  0.8               0
            .8  X 2  =  1.6               1
            .6  x 2  =  1.2                1
            ….

It again comes to .6 , that means the value will be repeated. It is similar like 4/3. The answer is never ending 1.333333333333333333 ….

Now it’s upto you to decide the number of digita you will take after the decimal point.

In a similar way, (14.6)10=(1110.1001)2 (taking 4 digit after point value)





Topic 10: Fractional value conversation from Binary to Decimal

If we start from the example below,

Example 10.1:

(1011.110)2=(?)10

For whole number part it will be like previous, but for the point value we it will be 2-1 , 2-2 , 2-3 and so on.. As you are better than me when it comes to mathematics, then you know the value for 2-1

Still who are having confusion,

2-1 means 1/21 = ½ = 0.5
2-2 means 1/22 = ¼  = 0.25
And so on ….


1  0  1  1  . 1  1  0
            x    x     x    x      x     x    x         
           23   22   21   20    2-1  2-2  2-3  
___________________________
=       8 +0 +2 +1    +.5 +.25 +0
=        11.75

So the answer is, (1011.110)2=(11.75)10



Example 10.2.

(11.0001)2 = (?)10

1  1  . 0  0  0  1
             x   x        x   x    x    x  
            21  20      2-1 2-2 2-3 2-4
___________________________
=        2 +1 +  0 + 0 +0 +.0625
=          3.0625


So the answer is (11.0001)2 = (3.0625)10


Topic 11: Fractional value conversation for Octal

Everything will be same as previous, just we need to use 8 everywhere instead of 2

Example 11.1:

(59.015625)10=(?)8

Step 1: for the integer part









Step 2: for the decimal part

.015625           X 8       = 0.125            0
.125                 X 8       = 1.0                1

So the answer is (59.015625)10=(73.01)8



Example 11.2:

 (52.15)8=(?)10

5 2  .  1  5
               x   x            x      x
            81 80       8-1  8-2
___________________________________________
           40+2  + .125 +.078125

So the answer is, (52.15)8 = (42.203125)10









Topic 12: Fractional value conversation for HexaDecimal

Everything will be same as previous, just we need to use 8 everywhere instead of 2

Example 12.1:

(59.015625)10=(?)16

Step 1: for the integer part









Step 2: for the decimal part

.015625           X 16     = 0.25              0
.125                 X 8       = 4.0                4

So the answer is (59.015625)10=(3B.04)8



Example 12.2:
 (52.15)16=(?)10

5 2  .  1  5
               x   x           x      x
           161 160  16-1 16-2
_________________________________
           80+2 + .0625 +.00390625

So the answer is, (52.15)16 = (82.06640625)10






Topic 13: Create your own number system

You can skip this part. Because this will never be in your academic syllabus. If you are really interested on computer science, now you have the idea that we can create our own number systems now. We will take 3 cases as below:



Case 1:

We can create a number system with base 4 and we can give it any name. Suppose I am naming this as Debabrata Number system.

So the conversion will follow the same rules as previous , but all the calculation will be based on 4

Example 13.1:

(52)10=(?)4










So the answer will be, (52)10=(310)4



Example 13.2:

(203)4=(?)10

2 0 3
x   x  x
42 41 40
______
32+0+3
=35

So the answer is (203)4=(35)10



Case 2:

Now we can invent a number series of base 20 , let’s name it Guha Number system.

So the digits we will use be using are like below:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K

I am not going to give any mathematical example anymore, but all the calculations will be based on 20 here.


Case 3:

We can also invent a number system with base 39 say. Let’s name it as “Students Number System”

Unique digits we can use

0-9 (10 icons) ,A-Z (26 icons)  and rest of the 3 icons will be invented by us say ψφϪ


So here all the calculations will be based on 39..








Hope everything is clear now related to number system. In case of any doubt, you can reach out to me. You can now start solving the exercise from the facebook album “General Computer Science Exercise”.

Comments

Popular posts from this blog

Java concepts Theory

About Myself ..