# Converting Between Decimal and Binary

Conversion of binary to decimal (base-2 to base-10) numbers and back is an important concept to understand as the binary numbering system forms the basis for all computer and digital systems. To understand IP address and IP address subnetting it is very important to learn conversion between binary and decimal.

## Binary to Decimal Conversion

The binary system is the internal language of the computer. For understanding IP addressing and subnetting, you should understand how to convert from binary to decimal and back. There are several ways to convert from binary to decimal. Here we will understand conversion from binary to decimal and then from decimal to binary.

Conversion Using Positional Notation

We have already learned positional notation in the previous lesson. This is one of the most used methods for conversion from binary to decimal. Let’s we want to convert the binary number 101111102 to decimal base 10 system using the positional system notation. See figure 1, First, write down the positional value from right to left. Then right binary number in the next row below the positional values. Next, multiply the binary with its positional value in the next row. Now add them up you will get the decimal number which is 189.

## We can just sample this method by writing positional values from right to left. The positional value is going double from right to left. For example from right to left first positional value is 1, the next one is 2, which is double of 1, the third place value is 4 which is double of the 2nd position value. We can write positional value by this method according to the digits of binary.

Now, just write the binary numbers below the positional values and map them up. Draw a line below these 2 lines. Now If the digit is a 1, write its corresponding positional value below the line, under the digit. If the digit is a 0, write a 0 below the line, under the digit. Now, add up the numbers written below the line. This is the decimal equivalent of the binary number. See figure 2 for this method.

## Now that you understand the basic conversion from binary to decimal, try converting a binary IPv4 address to its dotted-decimal equal. First, divide 32 bits of the IPv4 address into four 8-bit octets. Then calculate the binary positional value to the first octet binary number and calculate all others so.

For example, consider that 11010100.10101111.00101011.01001010 is the binary IPv4 address of a host. You need to convert the binary address to decimal, start with the first octet as shown in Figure 3. Enter the 8-bit binary number under the positional value of row 1 and then calculate to produce the decimal number for the first octet of the dotted decimal notation. Next convert the other 3 octets so see figure 4, figure 5 and figure 6. And write down the full IP address in dotted decimal notation.   ## Decimal to Binary Conversion

Decimal to binary conversion is also very necessary to understand, how to convert a dotted decimal IPv4 address to binary. For converting from decimal to binary, positional value table is very useful. Figure 7 illustrates the decimal to the binary conversion process. For example, we want to convert figure 212 into binary.

Step-1- if the decimal number (212) is equal to or greater than the most significant bit (128). If no, then enter binary 0 below the 128 positional value. If yes, then add a binary 1 below the 128 positional value and subtract 128 from the decimal number.

Step-2 -Compare if the remainder (84) is equal to or greater than the next-most-significant bit (64). If no, then add a binary 0 below the 64 positional value, if not add binary 1 and subtract 64 from the decimal remainder (84).

Step- 3 Compare if the remainder (20) is equal to or greater than the next-most-significant bit (32). If no, then add a binary 0 in the 32 positional value, otherwise, add binary 1 and subtract 32 from the decimal. Here we can see that the reminder is not greater than 32. So we will add 0 below the positional value and forward the remainder (20) to step 4.

## Step- 4 -Compare if the remainder (20) is equal to or greater than the next-most-significant bit (16). If no, then add a binary 0 below the 16 positional value, if not add binary 1 and subtract 16 from the decimal remainder (20).

Step- 5 -Compare if the remainder (4)  is equal to or greater than the next-most-significant bit (8). If no, then add a binary 0 below the 8 positional value, if not add binary 1 and subtract 8 from the decimal remainder (4).

Step- 6 -Compare if the remainder (4) of step 4 is equal to or greater than the next-most-significant bit (4). If no, then add a binary 0 below the 4 positional value, if not add binary 1 and subtract 4 from the decimal remainder (4).