'shift right/left (Bitwise Operators) in php7 gmp extension

enter image description here

What's the function name of shift right/left (Bitwise Operators) in php7 gmp extension? No something like gmp_shiftr found.



Solution 1:[1]

Notes contributed by Nitrogen. May be helpful for someone else too.

function gmp_shiftl($x,$n) { // shift left
  return(gmp_mul($x,gmp_pow(2,$n)));
}

function gmp_shiftr($x,$n) { // shift right
  return(gmp_div_q($x,gmp_pow(2,$n)));
}

For those who wish to do bitwise shifting, it's quite simple.. to shift left, just multiply the number by pow(2,x), and to shift right, divide by pow(2,x).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Time Killer