# Number Conversion - Decimal to Binary and Binary to Decimal

## Decimal to Binary:

Decimal (base-10) to binary (base-2) conversion:
Step 1: Divide the decimal number by 2 (2 comes from the base value of binary number system).
Step 2: The remainder is the LSB of the binary number.
Step 3: Divide the quotient from Step 1 by 2 again.
Step 4: The new remainder from Step 3 is the next digit (from right to left) of the binary number.
Step 5: The process continues until we get 0 as the quotient. The remainder from this step is the MSB of the binary number.

#### Example:

Decimal number: 4510
NumeratorDenominatorQuotientRemainder
452221 (LSB)
222110
11251
5221
2210
1201 (MSB)
So, the binary representation: 1011012

Decimal fraction to binary (base-2) conversion:
Step 1: Multiply the fraction number by 2 (2 comes from the base value of binary number system).
Step 2: The result (without the fraction part if any) is the MSB of the binary number.
Step 3: Take only the fraction part from Step 2 and multiply it by 2 again.
Step 4: The result (except the fraction part if any) from Step 3 is the next digit (from left to right) of the binary number.
Step 5: The process continues until we get X.00 as the final result (here X = 0 or 1). From this step X is the LSB of the binary number.

#### Example:

Decimal number: 0.62510
StepsMultiplicandMultiplierResult (without fraction part)Result (only the fraction part)
1.62521 (MSB).25
2.2520.5
3.521 (LSB).0
So, the binary representation: .1012

Decimal fraction to infinite binary (base-2) number conversion:
We will follow the same procedures explained in decimal fraction to binary (base-2) conversion, but here we will continue the steps until we obtain a repetition of a sequence of digits. If there's no repetition of digits, then we will stop after calculating up to our required number of digits.

#### Example:

Decimal number: 0.97510
StepsMultiplicandMultiplierResult (without fraction part)Result (only the fraction part)
1.97521 (MSB).95
2.9521.9
3.921.8
4.821.6
5.621.2
6.220.4
7.420.8
8.821.6
9.621.2
10.220.4
11.420.8
From the above table we can observe that steps 4-7 are repeated again and again.
So, the binary representation: .1111100110011001100.....2
Or, binary representation: .11111002

#### [Integer + fraction] decimal to binary [finite]:

Decimal: 45.62510
Binary: 101101.1012
A radix point [.] is used to separate the integer part (to the left of the radix point) of a number from its fractional part (to the right of the radix point).

#### [Integer + fraction] decimal to binary [infinite]:

Decimal: 45.97510
Binary: 101101.1111100110011001100.....2
Or, 101101.11111002

## Binary to Decimal:

Binary (base-2) to decimal (base-10) conversion:
From right (LSB) to left (MSB) we will take each digit and multiply them by 2x and later add the results together. Here x is the corresponding position of a digit and 2 comes from the base value of binary number system.

#### Example:

Binary number: 1011012
Number:1 (MSB)01101 (LSB)
Position:543210
(1 x 25) + (0 x 24) + (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20)
= 32 + 0 + 8 + 4 + 0 + 1
= 45

So, the decimal representation: 4510

Binary fraction to decimal fraction conversion:
From left (MSB) to right (LSB) we will take each digit and multiply them by 2x and later add the results together. Here x is the corresponding position of a digit and 2 comes from the base value of binary number system.

#### Example:

Binary number: .1012
Number:1 (MSB)01 (LSB)
Position:-1-2-3
(1 x 2-1) + (0 x 2-2) + (1 x 2-3)
= 0.5 + 0 + 0.125
= 0.625

So, the decimal representation: 0.62510

#### [Integer + fraction] binary to decimal:

Binary: 101101.1012
Decimal: 45.62510