From:             [EMAIL PROTECTED]
Operating system: Solaris 2.8
PHP version:      4.0.5
PHP Bug Type:     Math related
Bug description:  Incorrect results from logical AND

I'm using an integer to store an IP address as a 32-bit value rather than a
dotted-quad string and get odd results.  Since I'm only using it for
shifting bits, I don't think it should matter that PHP is missing an
unsigned integer type.

$foo = (255 << 24) | (111 << 16) | (241 << 8) | 254;
$octet[0] = ($foo & 0xff000000) >> 24;
$octet[1] = ($foo & 0x00ff0000) >> 16;
$octet[2] = ($foo & 0x0000ff00) >> 8;
$octet[3] = ($foo & 0x000000ff);
$quad = "$octet[0].$octet[1].$octet[2].$octet[3]";

The expected end result is that I get a dotted-quad string ($quad) that is
the same as was used to build $foo.

Instead, $octet[0] is miscalculated; it appears as "0" instead of 255. 
I've tried it for a variety of values and keep getting the same kind of
erroneous result.

However, if I change the statement to:
     $octet[0] = (($foo >> 8) & 0x00ff0000) >> 16;
I get the expected result.

Edit bug report at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to