From: Ashley Sheridan

> Out of interest, how does PHP calculate the IP number, as it was my
> understanding of IP numbers that they can't be negative.
> For example, my IP address is
> The four parts as binary:
> 01011001
> 11110011
> 10011100
> 10000111
> >From there, I thought that the binary values were concatenated as if
> they were a string, and then the decimal value worked out from that,
> giving, in my case, a value of 1509137543.
> How is it possible that PHP can produce negative values from this
> method? Does it do something else entirely, or is this a case of the
> integer value overflowing into negative values? (which might explain
> the value correctly converts back)

When stored as a four byte integer, the high bit becomes the sign flag.
So if the first byte is 128 or higher, it would be converted into a
negative number.

This is a common issue when the size of numbers exceed the storage space
allotted. It's well understood in tightly typed languages, but often
missed in the more loosely typed languages like Perl and PHP.

Bob McConnell

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to