|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-06-12 08:38 UTC] sysop at pkx dot pw
Description: ------------ --- From manual page: http://www.php.net/function.hexdec --- Test script: --------------- var_dump((int)hexdec(dechex(-9223372036854775805))); var_dump((int)hexdec(dechex(-9223372036854775804))); var_dump((int)hexdec(dechex(-9223372036854775803))); Expected result: ---------------- int(-9223372036854775808) int(-9223372036854775808) int(-9223372036854775808) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 15:00:01 2025 UTC |
> -9223372036854775808 is the same as the defined PHP_INT_MIN. echo dechex(-9223372036854775808); // 8000000000000000 which is the same as PHP_INT_MAX + 1. HexDec has no way of knowing which one you meant. > I guess as a whole php only supports unsigned numbers. No, in this very particular case PHP can't tell the difference. > I have try'ed to use pack with the q syntax however it outputs a invalid hexadecimal number as a whole, so thats wrong too. $packed = pack('J', -9223372036854775805); echo bin2hex($packed) . "\n"; var_dump(unpack('Jfoo', $packed)); // Output is 8000000000000003 array(1) { ["foo"]=> int(-9223372036854775805) } Please feel free to report a separate bug if you can make a reproduce case.