How to convert an IPV4 address into a integer

To convert an IPV4 address into an integer for purposes such as sorting you can use the following process:

First split the address into it's parts.

Then add each part together using the sum below:

(first octet * (256 ^ 3)) + (second octet * (256 ^ 2)) + (third octet * (256 ^ 1)) + (fourth octet)

Which equals:

(first octet * 16777216) + (second octet * 65536) + (third octet * 256) + (fourth octet)

Last updated: 21/06/2006