0

如何将十六进制 A67BFE427CBDC58F 转换为 int 64 签名 -6450282479763995249?

function bchexdec($hex) {
 if(strlen($hex) == 1) {
     return hexdec($hex);
 } else {
     $remain = substr($hex, 0, -1);
     $last = substr($hex, -1);
     $x = bcadd(bcmul(16, bchexdec($remain)), hexdec($last));
     return $x;
 }

bchexdec('A67BFE427CBDC58F') == 11996461593945556367。这是正确的,但没有符号((如何将无符号转换为有符号?

PHP 5.3+;PHP_INT_SIZE == 4

4

1 回答 1

1
if(bccomp($x, bcpow(2, 63)) >= 0) {
    $x = bcsub($x, bcpow(2, 64);
}
于 2013-02-10T02:15:07.057 回答