Integer (64-bit) division of large numbers without using intdiv() (before php7)

后端 未结 1 1385
执笔经年
执笔经年 2021-01-27 12:51

Tests are made at 64-bit system!

php7 has a nice function: intdiv(). The following code works perfect:

$number = 0x7fffffffffffffff;
$result         


        
1条回答
  •  温柔的废话
    2021-01-27 13:22

    You can use the % operator to get the remainder. Then after subtraction of the remainder perform the division:

    $rem = $number % 62;
    $result = ($number - $rem) / 62;
    

    0 讨论(0)
提交回复
热议问题