简体   繁体   English

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

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

When I run this: 当我运行这个:

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

32bit PHP returns: 24360257 32bit PHP返回: 24360257

64bit PHP returns: 103582791433958721 64bit PHP返回: 103582791433958721

How would I go about returning the 64bit answer on a 32bit install of php? 我将如何在32bit安装的php上返回64bit答案?
I have the BC extension if that makes a difference? 我可以使用BC扩展名吗?

You cannot shift more than 32 bits on a 32 bit processor. 在32位处理器上,移位不能超过32位。

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 整数的大小取决于平台,尽管通常的最大值约为20亿(32位带符号)。 64-bit platforms usually have a maximum value of about 9E18. 64位平台的最大值通常约为9E18。 PHP does not support unsigned integers. PHP不支持无符号整数。 Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5. 自PHP 4.4.0和PHP 5.0.5起,可以使用常数PHP_INT_SIZE确定整数大小,并使用常数PHP_INT_MAX确定最大值。

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

Don't know if it can be achieved with BC extension, but with GMP it is: 不知道是否可以使用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.

相关问题 如何将float转换为64bit二进制或将32bit float转换为64bit int-PHP - how convert float to 64bit binary or 32bit float to 64bit int - php 在WAMP 64位上将64位PHP转换为32位 - Convert 64bit PHP to 32bit on WAMP 64bit 在同一服务器上使用带有64位oracle客户端的php 7.3.4 64bit和带有32位oracle客户端的php 7.3.4 32bit - Using php 7.3.4 64bit with a 64bit oracle client and php 7.3.4 32bit with a 32bit oracle client on the same server 在64位debian上编译PHP扩展到32位PHP安装 - Compile PHP extension on 64bit debian to 32bit PHP installation 使用PHP计算32位系统上的按位64位运算 - Calculate bitwise 64bit operations on 32bit system with PHP 32位和64位ODBC驱动程序与PHP配合使用 - 32bit and 64bit ODBC Drivers playing nice with PHP 是否可以将Nginx 32位与php 64位一起使用? - Is it possible to use use Nginx 32bit with php 64bit? 如何在PHP中将两个无符号的32位整数合并为64位整数? - how to combine two unsigned 32bit integers to 64bit integer in php? 如何在 PHP 的 64 位安装上使用 32 位 integer? - How to use a 32bit integer on a 64bit installation of PHP? SSH2 dll未加载-Windows Server 2008 64位,PHP 5.3.5 32位,Apache 32位 - SSH2 dll not being loaded - windows server 2008 64bit, php 5.3.5 32bit, apache 32 bit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM