How to Convert Decimal to Binary?

Digital ElectronicsComputer EngineeringMCA

Decimal number is most familiar number system to the general public. It is base 10 which has only 10 symbols − 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. Whereas Binary number is most familiar number system to the digital systems, networking, and computer professionals. It is base 2 which has only 2 symbols: 0 and 1, these digits can be represented by off and on respectively.

Conversion from Decimal to Binary number system

There are various direct or indirect methods to convert a decimal number into binary number. In an indirect method, you need to convert a decimal number into other number system (e.g., octal or hexadecimal), then you can convert into binary number by converting each digit into binary number.

Example − Convert decimal number 125 into binary number.

First convert it into octal or hexadecimal number,
= (125)10
= (1x82+7x81+5x80)10
or (7x161+13x160)10
Because base of octal and hexadecimal are 8 and 16 respectively.
= (175)8
or (7D)16
Then convert it into binary number by converting each digit.
= (001 111 101)2
or (0111 1101)2
= (01111101)2

However, there are two direct methods are available for converting a decimal number into binary number: Performing Short Division by Two with Remainder (for integer part), Performing Short Multiplication by Two with result (For fractional part) and Descending Powers of Two and Subtraction. These are explained as following below.

(a) Performing Short Division by Two with Remainder (For integer part)

This is a straightforward method which involve dividing the number to be converted. Let decimal number is N then divide this number from 2 because base of binary number system is 2. Note down the value of remainder, which will be either 0 or 1. Again divide remaining decimal number till it became 0 and note every remainder of every step. Then write remainders from bottom to up (or in reverse order), which will be equivalent binary number of given decimal number. This is procedure for converting an integer decimal number, algorithm is given below.

  • Take decimal number as dividend.

  • Divide this number by 2 (2 is base of binary so divisor here).

  • Store the remainder in an array (it will be either 0 or 1 because of divisor 2).

  • Repeat the above two steps until the number is greater than zero.

  • Print the array in reverse order (which will be equivalent binary number of given decimal number).

Note that dividend (here given decimal number) is the number being divided, the divisor (here base of binary, i.e., 2) in the number by which the dividend is divided, and quotient (remaining divided decimal number) is the result of the division.

Example − Convert decimal number 112 into binary number.

Since given number is decimal integer number, so by using above algorithm performing short division by 2 with remainder.

DivisionRemainder (R)
112 / 2 = 560
56 / 2 = 280
28 / 2 = 140
14 / 2 = 70
7 / 2 = 31
3 / 2 = 11
1 / 2 = 01

Now, write remainder from bottom to up (in reverse order), this will be 1110000 which is equivalent binary number of decimal integer 112.

But above method can not convert fraction part of a mixed (a number with integer and fraction part) decimal number. For decimal fractional part, the method is explained as following below.

(b) Performing Short Multiplication by Two with result (For fractional part)

Let decimal fractional part is M then multiply this number from 2 because base of binary number system is 2. Note down the value of integer part, which will be either 0 or 1. Again multiply remaining decimal fractional number till it became 0 and note every integer part of result of every step. Then write noted results of integer part, which will be equivalent fraction binary number of given decimal number. This is procedure for converting an fractional decimal number, algorithm is given below.

  • Take decimal number as multiplicand.

  • Multiple this number by 2 (2 is base of binary so multiplier here).

  • Store the value of integer part of result in an array (it will be either 0 or 1 because of multiplier 2).

  • Repeat the above two steps until the number became zero.

  • Print the array (which will be equivalent fractional binary number of given decimal fractional number).

Note that a multiplicand (here decimal fractional number) is that to be multiplied by multiplier (here base of 2, i.e., 2)

Example − Convert decimal fractional number 0.8125 into binary number.

Since given number is decimal fractional number, so by using above algorithm performing short multiplication by 2 with integer part.

MultiplicationResultant integer part (R)
0.81252 x 2= 1.6251
0.6252 x 2= 1.251
0.252 x 2= 0.500
0.52 x 2= 1.01
0 x 2 = 00

Now, write these resultant integer part, this will be 0.11010 which is equivalent binary fractional number of decimal fractional 0.8125.

Descending Powers of Two and Subtraction

This method is gussing binary number of a decimal number. You need to draw a table of power of 2, then take given decimal number and subtract it from maximum possible power of 2 that does not return resultant number negative. Then put 1 into that box of this power in the table. Repeat these steps till number is greater than zero. Put a 0 in all other empty boxes and take the output which will be equivalent binary number of given decimal number. For integer part, The algorithm is explained as following below.

  • Start by making a chart.

  • Look for the greatest power of 2.

  • Move to the next lower power of two.

  • Subtract each successive number that can fit, and mark it with a 1.

  • Continue until you reach the end of your chart.

  • Write out the binary answer.

Example − Convert decimal number 205 into binary number.

Take table of power of 2,

Decimal27 = 12826 = 6425 = 3224 = 1623 = 822 = 421 = 220 = 1
Binary11001101


Subtract given number 205 from maximum possible power of 2,
= 205 - 128 = 77
Put 1 in box of 128 (= 27), then again subtract remaining number 77 from maximum possible power of 2,
= 77 - 64 =13
Put 1 in box of 64 (= 26), then repeat above steps,
= 13 - 8 =5
= 5 - 4 =1
= 1 - 1 =0
And put a 0 in remaining boxes. Therefore equivalent binary number will be 11001101 of given 205 decimal number.
raja
Published on 06-Dec-2018 15:12:44
Advertisements