$steamID = 76561198021498838; $temp = 4294967295; $steamID = $steamID & $temp;

If you count this on a calculator, you get 61233110, but if this code is processed on the server, it returns 61233104, that is, it is mistaken for 1 and 2 bits. Tell me what's the problem?

    1 answer 1

    Integer overflow
    If PHP finds that the number is larger than the integer type, it will interpret it as a float. Similarly, if the result of an operation is outside the integer type, it will be converted to float.

    http://php.net/manual/ru/language.types.integer.php
    and try this code:

     $x=4294967295; // это срез Вашего числа, чтобы не было переполнения $y=4356200406; echo $x & $y; 

    To understand what the overflow really happened, do

     echo $steamID; // 7.6561198021499E+16 

    How to solve this problem:

     $x=gmp_init("76561198021498838"); $y=gmp_init("4294967295"); echo gmp_strval(gmp_and($x, $y)); // 61233110 
    • Thank you so much for the advice. Since the gmp library is not connected on my server, I decided to let it be, and I solved the problem with the help of the already connected BC Math, and did all the bitwise operations manually. - omartio