Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hexdec produces a result larger than 2147483647

Status
Not open for further replies.

Guggly

Programmer
Joined
Jan 18, 2004
Messages
110
Location
US
Hi! When I convert the below hex string into a decimal number with the hexdec function, it gives me a result of 3892131585. This is technically correct in that it's the unsigned result. However, I need PHP to return the signed result from this function which is -402835711.

The PHP reference for the hexdec and dechex functions says "The largest number that can be converted is 7fffffff or 2147483647 in decimal." Am I assuming incorrectly that this means PHP should return a signed result? Either way, how can I get it to not return an unsigned value??

hexdec("E7FD3701") = 3892131585

Thanks! -- Mike
 
Okay, if I cast it into an integer data type it works fine using the following:

Code:
$result = (int) hexdec("E7FD3701")

Too bad I can't give myself a star :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top