This week on “I learn a weird, semi-useless skill” brings you how I learn to convert 32 bit IP addresses into their binary counter part and back. If I asked you if you have ever or would ever need this knowledge, you’d probably say no. But the learning must continue!
Firstly, lets pick an IP address, this can be any random combination of 4 pairs of 3 digits between 0 and 255. For this guide, I’ll be using 126.96.36.199. For no apparent reason.
So to convert this number into binary, I use a simple table method. You can see the table below:
This table makes it very simple to work out how to convert each of the four octets in an IP address to binary.
First we start with 176
We go through each of the numbers in the table above and see if the column number can be subtracted from the first octet of the 32-bit address. So our first step would be, can we subtract 128 from 176?
The answer is YES so I would put a “1” in the 128 column, and our remainder from the above sum is “48“. Your table should look similar to the one below.
Now we can do the next step using our remainder of “48“. Can we subtract 64 from 48?
The answer is NO so I would put a “0” in the 64 column. When the answer is no, then the remainder stays the same, so the next sum would be, can we subtract 32 from 48? This goes on until you are at the end of the table and your remainder should be 0.
The finished table for the 176 part is shown below:
Once you have done this for all 4 octets in the IP address, you should end up with 4 tables filled with 1’s and 0’s. The full binary number for our IP address is:
Converting Binary to the 32-bit IP address is quite a lot simpler. Once again we use the same table but this time we put the binary number into the table and read which numbers have a 1 and which numbers have a 0 in the column.
For example, plugging the binary of “176” into the table gives us the below result:
From this we can see that the following columns have a 1 assigned to them:
Now all we have to do is add these numbers together to get the first octet of the 32-bit address, which is “176“. Now do this process for the other 3 parts of the binary address and you will get back the original IP address of “188.8.131.52”
I would suggest doing this exercise multiple times to really nail it if you need to. Who knows, if you and your company are really sad and nerdy, this might be a nice party trick. Or a particularly cringey 15 minutes.
I think I explained this well enough. If not, please comment and let me know what parts I could improve or add. Enjoy!
P.S You have also want to use this form I created to do this activity: Converting 32-Bit Address to Binary and Back