繁体   English   中英

PHP-在32位php安装上需要64位输出

[英]PHP - Need the 64bit output on a 32bit php install

当我运行这个:

echo ((1 << 56) | (7 << 52) | 4437313);

32bit PHP返回: 24360257

64bit PHP返回: 103582791433958721

我将如何在32bit安装的php上返回64bit答案?
我可以使用BC扩展名吗?

在32位处理器上,移位不能超过32位。

整数的大小取决于平台,尽管通常的最大值约为20亿(32位带符号)。 64位平台的最大值通常约为9E18。 PHP不支持无符号整数。 自PHP 4.4.0和PHP 5.0.5起,可以使用常数PHP_INT_SIZE确定整数大小,并使用常数PHP_INT_MAX确定最大值。

http://php.net/manual/en/language.types.integer.php

不知道是否可以使用BC扩展来实现,但是使用GMP可以达到:

function gmp_shiftl($x,$n) {
    return gmp_mul($x, gmp_pow(2, $n)); 
}
$res = gmp_or(gmp_or(gmp_shiftl('1','56'), gmp_shiftl('7','52')), '4437313');
echo gmp_strval($res);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM