Re: Can someone explain this?
| From: | Curt Zirzow | Date: | Tue, 08 Jun 2004 17:29:42 +0000 |
| Subject: | Re: Can someone explain this? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-187899@lists.php.net to get a copy of this message | ||
* Thus wrote Ren Fournier (m5@renefournier.com):
> -= 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!