FANDOM


Overview Edit

Notes, notes, notes...

IPv4 Address to Integer Edit

To convert an IP address to integer, break it into four octets. E.g.:

First Octet: 	58
Second Octet: 	71
Third Octet: 	34
Fourth Octet: 	137
To calculate the decimal address from a dotted string, perform the following calculation.


	(first octet * 256^3) + (second octet * 256^2) + (third octet * 256) + (fourth octet)
= 	(first octet * 16777216) + (second octet * 65536) + (third octet * 256) + (fourth octet)
= 	(58 * 16777216) + (71 * 65536) + (34 * 256) + (137)
= 	977740425

or

Convert each octet to binary, append them, and convert the resulting string into decimal.

Use ip2long() in PHP.

IPv6 Address to Integer Edit

Hmmm... maybe I'll just strip off the colons and convert from hex to decimal?

Integer to IPv4 Address Edit

Integer to IPv6 Address Edit