# Conversions

In this, we will learn about the conversions. First two conversions viz. Binary to Decimal and Decimal to Binary are explained in detail and remaining two conversions viz. Decimal to Hexadecimal and Hexadecimal to Decimal are almost same as first two but with small difference.

In all the conversions, we will take one number and convert in to another.

Binary to Decimal
Binary number is represented with 0 and 1.

Binary Number: 0110 0011
Rightmost bit of binary number is LSB i.e. Least Significant bit and leftmost bit is MSB (Most Significant bit).
This means that LSB is 1 and MSB is 0

Conversion procedure
To convert the binary number in to decimal number, we will start go from LSB to MSB and give it a position.

Number: 0             1              1              0              0              0              1              1
Bit Pos:    7              6              5              4              3              2              1              0
Decimal:  0*2     1*26       1*25       0*24       0*23       0*22       1*21       1*20

Each bit of binary number is represent in decimal number using (bit*2POS)
Decimal Number will be sum of all the above decimal values:
0*2 +  1*26   + 1*25   + 0*24   +   0*23  +  0*22  +   1*21   +    1*20  =  99

In this, we have shown 8-bit binary number. 8-bit binary number is called an octet.
Maximum decimal value of an 8-bit binary is 255 i.e. all 1s

Decimal to Binary
Decimal number can be represented using ten digits ranging from 0 to 9.
E.g. 10, 54, 88, 99, 567

Conversion Procedure
Step1: Divide the number by 2(since we need to convert in to binary) and store the remainder (This will be the LSB of binary).
Step2: Set the number from the above quotient, divide it again by 2, and store the remainder.
Step3: Perform the step 2 until the number is greater than or equal to 2.
Step 4: Once the above loop overs, store the quotient (This will be the MSB of the binary) and remainder both from last step

Based on above steps, lets convert 99 in to binary

Step 1: 99/2 = 49, remainder = 1
Step2: Number = 49, 49/2 = 24, remainder = 1
Loop over step 2
Number = 24, 24/2 = 12, remainder = 0
Number = 12, 12/2 = 6, remainder = 0
Number = 6, 6/2 = 3, remainder = 0
Number =3, 3/2 = 1, remainder = 1 –> This is the termination point of loop since the number is now less than 2.

Binary number is formed from the remainder value stored in each step and from quotient of last step.

Binary Number: 1 1 0 0 0 1 1

Hexadecimal number is represented using 16 numbers range from 0 to 15. But in hexadecimal notation, 10 to 15 are mapped to A to F i.e. 10 is represented by A, 11 is represented by B and so on.

Conversion Procedure
Steps to convert decimal in to hexadecimal are same as decimal to binary. Only difference is that dividing number will be 16 instead of 2.
Decimal Number: 99
Step 1: 99/16 = 6, remainder = 3

That is it. Hexadecimal Number for 99 is 63