# Converting IPV4 address into Binary

So given an IP address it is converted into binary via calculating the binary of all different segments and then joining them. For example, 12.32.18.01 converted into a binary it would amount to this number in decimal form 12*2^24 + 32*2^16 + 18*8 + 01 My question is why to go through all this trouble and calculation. Why not just get rid of the dots in the original Ip and then convert that integer into binary. So, for this example, the binary of the above example would amount to this integer in decimal 112 032 018 001. I mean what's the problem with second approach?

• Are you asking why a machine does not use this approach specified or why you shouldn't use it ? Dec 15 '19 at 0:52
• Ya I meant why machines don't use it in the first place Dec 15 '19 at 3:25

I am going to answer this question in two parts:
First,
Without reaching into the depths of communication, I want to mention that the data that humans do understand(such as this answer which I am typing) is classified under Layer 7 of the TCP/IP stack. This data gets converted into analog signals that travel over the wire, and any hosts connected to these wires translate these analog signals to electric signals. Electric signals have two states, 0 and 1, which we humans call binary format. So any data on the wire would essentially be looked upon as a sequence of bits and bytes.

Second,
The conversion that you mentioned, between binary and dotted decimal, is purely for representing data in human readable format(as the other answer mentions). Tools like Wireshark do this to show details of a packet(the internals of this are fascinating). So, you can choose whichever method to convert one form to the other, but the machines don't really need to do this at the level of the TCP/IP stack where it really matters. The system doesn't really see it as a dotted decimal construct, but a data structure which consists of four 8 byte fields, (or two 16).

Hope this helps !

The dotted-decimal notation for IP Addresses is specifically a "human-readable" format. e.g. IP address 192.168.0.0 is from a private address range. The reason I mentioned "private" is to emphasize on the usefulness of dotted-decimal representation to analyze the classes/subnets that a given IP address represents.

Now, you're right that we could get rid of the dots and directly convert the IP address into an integer. But, it doesn't matter because computers understand numbers (including IP address) only in binary. So, although following notations represent one and the same thing, you might be interested in different notations based on the use-case: studying to grasp concepts, analyzing classes/subnets or debugging actual packet data from the network interface(which will be just a string of zeros/ones).

192.168.0.0 = 3232235520 = 0xC0A80000 = 0b‭11000000101010000000000000000000‬

• Okay, so what I understand is that this notation provides us much more information about the network and encodes it on various levels. Something like classes Dec 15 '19 at 2:38
• Yes you're right. Try exploring more about classes/subnets and also the IPv6 format and I'm sure you'll appreciate it.
– ss09
Dec 15 '19 at 2:50
• Thanks that was helpful Dec 15 '19 at 3:10