Attempt greater than PHP_INT_MAX

On a 64-bit server, I tried this:

$a= hexdec("FFFFFFFFFFFFFFFF");
print($a."<br>");
printf("%d", $a);

and here is the output:
1.84467440737E+19
0

I expected to get -1 as this would be greater than PHP_INT_MAX. why didn’t I get -1? and what does the number above mean? and how to get -1 for this?

means 1.84467440737 x 10^19 or 18 446 744 073 700 000 000

so what to do with it? do I have to run hexdec() to this to get the value you gave? why %i does not return 1 as it looks like a float?and shouldn’t it be -1 on a 64-bit server?

Can you print PHP_INT_MAX and tell us what you get?

on 64-bits, obviously I got: 9223372036854775807
and again to hex obviously I got: 7fffffffffffffff
so why with 16x F, I didn’t get -1? why 1.84467440737E+19 ? and what does it mean?

From the PHP.net manual page about the hexdec() function.

Note:
The function can convert numbers that are too large to fit into the platforms integer type, larger values are returned as float in that case.

Scott

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.