$s = '9C216AFB868C';$sb=hexdec($s) ;var_dump( $sb );//1.716673427227E+14echo '
';var_dump( dechex($sb) );//6afb868c
The hexadecimal $s is converted to decimal, and then the hex is reversed.
dechex()
there is a limit to the size of the conversion.
------------Supplement---------------------------------------
$s = ' 9c216afb868c ';
How does the $s plus 1 php come true? (hexadecimal calculation)
Reply content:
$s = '9C216AFB868C';$sb=hexdec($s) ;var_dump( $sb );//1.716673427227E+14echo '
';var_dump( dechex($sb) );//6afb868c
The hexadecimal $s is converted to decimal, and then the hex is reversed.
dechex()
there is a limit to the size of the conversion.
------------Supplement---------------------------------------
$s = ' 9c216afb868c ';
How does the $s plus 1 php come true? (hexadecimal calculation)
In contrast, the final output 6afb868c
is exactly 9C216AFB868C
the back 8 bits (ignoring case).
In the HEXDEC manual, the following:
Starting with PHP 4.1.0, this function can handle an integer large number, in which case it returns a float type.
In the Dechex:
The maximum value that can be converted is the decimal Php_int_max * 2 + 1 (or-1): The 32-bit platform is a decimal 4294967295, and the result of its dechex () is ffffffff.
The first result 1.716673427227E+14
is written in normal format 171667342722700
, and the result has no problem.
9c216afb868c
Go to decimal: http://www.wolframalpha.com/input/?i=convert++9c216afb868c+to+base+10
This number is again converted back to be 9c216afb868c
.
171667342722700
Ext. 16: Http://www.wolframalpha.com/input/?i=171667342722700+to+hex
First of all, if you are not a 32-bit computer, this number is far from the maximum value that PHP can handle, the maximum value in PHP can be PHP_INT_MAX
found in the constant, under the 64-bit computer its value is
echo PHP_INT_MAX; // 9223372036854775807echo dechex(PHP_INT_MAX); // 7fffffffffffffff
And you can be successful from 16 into the system, it is impossible to turn back because of the size problem . The problem is that the 10 binary value that you turn out is
1.716673427227E+14
This is a string expressed in scientific notation, and the dechex
function is not able to recognize the string, andPHP will only automatically convert a string of pure numbers into a corresponding shaping or floating point .