How to calculate binary numbers (For example IPv4 address)

In this post I thought to write down something about how to calculate binary numbers because recently there was a discussion about it and I realized that I had forgotten everything about it and the internet, although it has a good information about how to calculate the binary, the information is scattered in over many websites. So in order for you to use the information you must know what you are looking for but anyway here is illustration on how to do the calculation. I will try to update this section with better information and content.

IPv4 addresses can only have 4 octets, meaning that it can only have 4 parts for example where the value before the dot(.) is called an octet. In my opinion the octect can hold the value between 0-255. You can search more information related to this in the internet or books.

This octet always has a binary value where the binary is always 8 digits long meaning (01010101) where the the binary is usually read and calculated from right to left (but I do it from left to right for the sake of clarity). The binary value cannot hold more than 8 or less than 8 digits but the values can be different meaning they can be either 0 or 1.

The way you calculate the binary is in the following way. For example if you were to calculate the first octet where the value is 254, you would first have to know how to calculate from binary into ordinary numerical value. Remember this before we go to calculate that 1 is on, and 0 is off. The on and off might not make sense right now but it will make sense shortly.

Like I said before you must always have 8 digits for example in our calculation it would be


Now the above might look scary if you would think, how in the world you can get the value 254 but its very simple. In fact its 101% easier than most websites show with all their special effect fonts, images and colors. What basically happens is that if 1 = on then you would calculate that digit to the power of 2. You just add the more you go from left to right and you always have 0 in the first digit. This is hard to explain but the example is in the below. Where n signifies to the power of for example 3(n2) equals 9

Binary:           1            1            1           1         1           1           1            0
Calculation: 2(n7) + 2(n6) + 2(n5) + 2(n4) + 2(n3) + 2(n2) + 2(n1) + 2(n0)
Value:            128  +   64   +    32   +   16   +   8      +   4     +    2     +     0

SUM: 254

The previous in mind you can memorize the rules so that you do not have to calculate like this every time. You can just add the numbers together if the binary above its position is 1. If the digit is 0 then you skip that part for example

00001000 equals to 0 + 0 + 0 + 0 + 8 + 0 + 0 + 0 where the sum is 8. Its so easy!
If you would have wanted the max 255 value the binary would have been 11111111.
With the previous in mind here is a link to a website concerning ASCII alphabets

I also strongly advice you to check if I am right or not, so you will not take all of this for granted.

Here is an update with a link to a very good PDF file I found from the internet through a course class website. Click here to redirect.