Use of bit operations on 64-bit integers on 32-bit systems (without php_gpm extension)

I found some solution. An efficient way to perform 64-bit rotation using 32-bit values , but this is not in PHP.

The biggest problem is what I get from a remote large server 9223372036854775808(10)like hexadecimal 8000000000000000(16).

There is no way to enable it php_gmp (extension)on the production server, but I have to check the selected bits in the received value. Both production and development servers 32bits machines.

+3
source share
1 answer

, ( ):

BC Math . BC Maths , , BC Math .

http://php.net/manual/en/ref.bc.php

PHP BC Math; PHP .

, , BC Math . ; Google, , :

function bitValue($no) { return bcpow(2, $no); }
function bitSet($no, $value) {
    $tmp = bcmod($value, bitValue($no+1));
    return bccomp(bcsub($tmp, bitValue($no)), 0)>= 0;
}

echo bitSet(49, bitValue(48)) ."\n";
echo bitSet(48, bitValue(48)) ."\n";
echo bitSet(47, bitValue(48)) ."\n";

( hernst42)

+1

Source: https://habr.com/ru/post/1778756/


All Articles