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

Posted by Victor Stanciu on Stack Overflow See other posts from Stack Overflow or by Victor Stanciu
Published on 2010-03-17T11:48:30Z Indexed on 2010/03/17 11:51 UTC
Read the original article Hit count: 477

Filed under:
|
|
|

Hello,

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. For example:

echo(516103988<<32); // echoes 516103988

Because shifting the bits to the left one space is the equivalent of multiplying by 2, i tried multiplying the number by 2^32, and it works, it returns 2216649749795176448.

Second: I have to add 9379 to the number from the above point:

printf('%0.0f', 2216649749795176448 + 9379); // prints 2216649749795185920 

Should print: 2216649749795185827

© Stack Overflow or respective owner

Related posts about php

Related posts about bitwise