The easiest way to learn these conversions is through the use of examples, so for the first one, you should see each number as an octet, of 8 bits. For instance, we will take a number of 254, from let’s say an IP address of 192.168.0.254. What we are trying to do next, is to convert the binary number 11111110 which we know is an octet and it represents 254 in decimal value, and understand the conversion process behind it.
The maximum number for an octet can be 255 and this is if all the 8 bits have a value of 1. Imagine each of the 8 bits is a power of 2, if you put this inside a table you should have something like this:
All the values in the decimal cells, added together will give the maximum number that an octet can have which is 255, this is if all the bit positions are set to 1 and you have a binary value of 11111111.
Now let’s go back to that example we were trying to do, converting 11111110 to a decimal value. For this, we will need to remember the bit positions, which you could call exponents row too. The best way to do the conversions is with the help of this table and method.
Now, the concept behind this is that you start with the biggest exponent which would be 27 and for each value of 1 in the binary row, you should add the decimal value of the position to the actual number we will get in the end. 0 means we will ignore the field and the value.
So the first position, 27 we see in the binary row a 1, this means we will add the decimal to the actual number. To better understand, we will also write the actual value in the decimal row, so we first have an 128. Second position which stands for 64, we have a binary 1 which says we need to add this one too so we have 128+64 until this point for the actual decimal size. We will add all the rest of the values meaning 128+64+32+16+8+4+2 until we find a 0 on the binary row. Then we add 0 to the decimal number because it doesn’t count. The 0 tells us this field is to be ignored as you can see below.
The final decimal number will be 254.
The same method applies if you are trying to convert an entire IP address, the only thing different is that you will have to do it for each octet as there is no way to do it for all the octets at the same time. In time, after practicing a little, you will be able to calculate the octets in your head, without the help of the table.