"Jonathan Rosenberg" <[EMAIL PROTECTED]> wrote in message

> would produce the same output.  Is this correct?


> Either I'm missing something, or PHP gets very confused when
> dealing with some numbers.  For example, the following program
> <?
> $result = 0x9E3779B9;
> echo $result
> printf('%d', $result);
> ?>
> produces
> 2654435769
> -1640531527
> I get the same kind of unexpected results when doing arithmetic
> on such numbers.
> Is this tickling some kind of known bug in PHP?  or am I
> misunderstanding something?

It's not a bug, just an 'inconsistency'. Both are correct... if you have a
calculator that supports hex, type both those results in and convert to hex.
Both should say 9E3779B9. The first result treats 9E3779B9 as an unsigned
32-bit value, the second result treats it as a _signed_ 32-bit value. If you

printf('%u', $result);

(assuming PHP supports the full range of C printf() format specifiers), it
should print out 2654435769 as does the straight echo.

It seems echo treats numbers as unsigned...

When doing arithmetic in code, you should always be prepared to handle
signed and unsigned.

_ _
o o    Jason Teagle

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to