Check out Scrivo

Do you want to try out Scrivo? Then here's a demo for you that does not just get your feet wet but lets you plunge right in.

Contact us

For more information, please contact us. We're happy to help you out!

Next Oct 9 Previous

Big integers keep us connected

IP addresses which are commonly represented as strings like "" are actually 4 byte (32 bit) integer numbers. If you want to convert an IP address string to an integer number you don't have to do the math yourself; there is a PHP function for it. Which function is this:

A: ip2int()
B: ip_to_int()
C: ip2long()
D: intval()
E: ip_convert()


It's ip2long() and the other way round is long2ip(). All other answer possibilities except intval() are just made up function names. And intval() will not be able to digest an IP address string of course.

But where does this "long" in those function names come from?

The C programming language has a whole bunch of different types of integers depending on their size. The standard integer in C is named int and (usually) 16 bit in size. An IP address or other larger number is not going to fit into 16 bit so C has a different integer type for larger 32 bit integers. This type is called long int or just long because C programmers hate to type. This is the "long" to which these function names refer to.

PHP doesn't have long integer types as C does nor is ip2long() a standard C or POSIX function, so these names were not to well chosen if you'd ask me.