Re[4]: [PHP] unexpected results using sprintf() with %u
| From: | Tom Rogers | Date: | Fri, 03 Oct 2003 06:59:52 +0000 |
| Subject: | Re[4]: [PHP] unexpected results using sprintf() with %u | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-164864@lists.php.net to get a copy of this message | ||
Hi,
Friday, October 3, 2003, 4:39:32 PM, you wrote:
CP> Yeah abs() looks like it would do the trick
CP> I wonder if the same output would be generated using C's sprintf()
CP> Too bad i dont have access to C... oh well
>> -----Original Message-----
>> From: Tom Rogers [mailto:trogers@kwikin.com]
>> Sent: Friday, 3 October 2003 16:27
>> To: Tom Rogers
>> Cc: Cody Phanekham; php-general@lists.php.net
>> Subject: Re[2]: [PHP] unexpected results using sprintf() with %u
>>
>>
>> Hi,
>>
>> TR> -86 actually looks like FFFFFFAA which if you then look
>> at unsigned is pretty
>> TR> big :)
>>
>> TR> --
>> TR> regards,
>> TR> Tom
>>
>> Maybe what you need is the abs() function which ignores the
>> sign of a number
>>
>> --
>> regards,
>> Tom
>>
>>
>>
CP> *************************************************************************************
CP> This e-mail, including any attachments to it, may contain confidential and/or personal
CP> information.
CP> If you have received this e-mail in error, you must not copy,
CP> distribute, or disclose it, use or take any action
CP> based on the information contained within it.
CP> Please notify the sender immediately by return e-mail of the error and then delete the
CP> original e-mail.
CP> The information contained within this e-mail may be solely the opinion
CP> of the sender and may not necessarily
CP> reflect the position, beliefs or opinions of Salmat on any issue.
CP> This email has been swept for the presence of computer viruses known to Salmat's
CP> anti-virus systems.
CP> For more information, visit our website at www.salmat.com.au.
CP> *************************************************************************************
C would do exactly the same, it is the way in which negative numbers are
represented
1 = 01 in hex
0 = 00 in hex
-1 = FF in hex
-2 = FE in hex
now if we forget about being negative FF becomes 255 and FE becomes 254 and so
on. Where they cross over is 7F is the largest positive and 80 is the most
negative (using 1 byte). Using 2 bytes it would be 7FFF and 8000.
Hope that explains it
--
regards,
Tom