Re: [PHP] stripping negative number
On Thursday 23 December 2004 16:18, Roger Thomas wrote: > I want to convert negative number to its positive equivalent. > > $num = -40; > printf("Unsigned value is %u", $num); > > output is: Unsigned value is 4294967256 > > I have checked the manpages and %u seems the right format. Pls advise. You've misunderstood what the unsigned representation means. The correct function to use is abs(). -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* No matter whether th' constitution follows th' flag or not, th' supreme court follows th' iliction returns. ollo -- Mr. Dooley */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping negative number
I believe this is because taking a value and displaying it as an unsigned value isn't the same as displaying the absolute value of a number. Ever take a calculator that does hex and decimal, enter a negative number then convert it to hex? There's no negative in hex, so you end up with something odd (like zero minus one equals max value of unsigned hex.. so -40 would be 40 below the max value or something... don't know exactly how it works but I'm guessing that's what you're getting here). You might want to just use abs() to get the absolute value of the number before displaying it. -TG = = = Original message = = = I want to convert negative number to its positive equivalent. $num = -40; printf("Unsigned value is %u", $num); output is: Unsigned value is 4294967256 I have checked the manpages and %u seems the right format. Pls advise. -- roger --- Sign Up for free Email at http://ureg.home.net.my/ --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripping negative number
unsigned does not equal absolute value. $num = -40; print "Num: $num\n"; $num = abs($num); print "ABS: $num\n"; will display: Num: -40 ABS: 40 http://us2.php.net/manual/en/function.abs.php Justin - Original Message - From: "Roger Thomas" <[EMAIL PROTECTED]> To: Sent: Thursday, December 23, 2004 1:18 AM Subject: [PHP] stripping negative number I want to convert negative number to its positive equivalent. $num = -40; printf("Unsigned value is %u", $num); output is: Unsigned value is 4294967256 I have checked the manpages and %u seems the right format. Pls advise. -- roger --- Sign Up for free Email at http://ureg.home.net.my/ --- -- 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
[PHP] stripping negative number
I want to convert negative number to its positive equivalent. $num = -40; printf("Unsigned value is %u", $num); output is: Unsigned value is 4294967256 I have checked the manpages and %u seems the right format. Pls advise. -- roger --- Sign Up for free Email at http://ureg.home.net.my/ --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php