$unpacked = unpack('Nval', $msg); // N for unsigned long integer, big-endian (SPARC)
echo $unpacked["val"];
...the output value is "-333371788". (???) Which tells me that PHP is NOT unpacking $msg as an unsigned long integer, but rather as a signed integer (since unsigned integers cannot be negative).
Now, thanks to your suggestions, I can convert that number back to an unsigned integer—or at least make it positive. But I shouldn't have to convert it, should I?
...Rene
On Tuesday, June 8, 2004, at 11:29 AM, Curt Zirzow wrote:
* Thus wrote Ren Fournier ([EMAIL PROTECTED]):-= PRODUCES: =-
-333371788 3961595508
Is this something about signed versus unsigned integers? What I really would like to do is convert that negative number (-333371788), which I suppose is unsigned to a signed integer (3961595508) without having to convert it to hex, then back to decimal.
You have it backwords.. -333371788 is signed and the 3961595508 is unsigned.
But...
<?php $dec = -333371788; $unsigned = sprintf("%ul", $dec); print $unsigned; // == 3961595508
Do note that php doesn't have native unsigned numbers so doing something like this wont work right:
printf("%d", $unsigned); // == 2147483647
So to convert it back you have to do something like: printf("%d", $unsigned+0); // == -333371788
Curt
--
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about. No, sir. Our model is the trapezoid!
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php