Re: stripping negative number

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux