PHP bitwise left shifting 32 spaces problem and bad results with large numbers arithmetic operations

前端 未结 3 834
甜味超标
甜味超标 2021-01-06 16:31

I have the following problems:

First: I am trying to do a 32-spaces bitwise left shift on a large number, and for some reason the number is always returned as-is. Fo

3条回答
  •  攒了一身酷
    2021-01-06 16:56

    Php integer precision is limited to machine word size (32, 64). To work with arbitrary precision integers you have to store them as strings and use bc or gmp library:

       echo bcmul('516103988', bcpow(2, 32));  // 2216649749795176448
    

提交回复
热议问题