Your source for electronics

Cheat Sheet : Binary Number Conversion

Decimal to Binary : 

There are two methods to convert a decimal number to the binary numeral system : sum of weights or the repeated division by 2. Both methods can be used for all integers numbers and you can used the method you prefer. We recommend using the repeated division by 2.

Sum of weights

Figure 1 : Weights of the first 7 digits of the binary numeral system

The sum of weights consist of adding the weights of one or multiples digits to get the decimal number desired. Since we know the weight value of each binary digit, we can then add them together to get the decimal number. The digits that are used to get the decimal number are going to be “1” and the other which aren’t used are going to be “0”. If 7 digits are not enough, you can find the weight value of the next digit by multiplying by 2 the decimal weight value to its right.

Example : we want to find the binary number of the decimal number 25. To get the decimal number 25, we need to add the weights 16, 8 and 1. 16 + 8 + 1 = 25. We need the first, fourth and fifth digits to represent the decimal number 25. These digits needs to be 1s.

11001_{2} = 16 + 8 + 1 = 25_{10}

Repeated division by 2

The repeated division by 2 is generally prefer for bigger integer number. For any decimal number, we start by dividing by 2. The remainder from each division forms the binary number. We divide by 2 until we get 0. The remainder of the first division is the first digit of the binary number or the right most digit (often called the least significative bit LSB). The remainder of the last division is the left most digit (often called the most significative bit MSB). Below, you can find an example for the decimal number 27.

Figure 2 : Repeated division by 2 for decimal number 27

Binary to Decimal : 

Sum of weights

The method to convert a binary number to a decimal number is done with the sum of weights. Each digits has a weight (or value if you prefer). You will need to add together the weight value of each digits in the binary number with a value of “1” to get the decimal value. Below, you can find an example for reference :

We have the binary number “110101” that we want to convert to a decimal number. We need to add together the weight of each digits that is a “1” in the binary number.

Figure 3 : Binary number 110101

\textbf{1} \cdot 2^{5} + \textbf{1} \cdot 2^{4} + \textbf{0} \cdot 2^{3} + \textbf{1} \cdot 2^{2} + \textbf{0} \cdot 2^{1} + \textbf{1} \cdot 2^{0}

32 + 16 + 4 + 1 = 53

This binary number is the decimal number “53”.