Binary Shift: Signed or Unsigned?

php.internals

Alex Stapleton

22 years ago
Are << and >> signed or not? E.g. is 1100 >> 1 = 1110 or 0110? I am using PHP5, if I want unsigned binary shift, do i have any options other than converting to a string using base_convert and writing my own function to shift the bits and then convert back to a number? Is what i am after planned if not availible already?

Christian Schneider

22 years ago
Alex Stapleton wrote:
> I am using PHP5, if I want unsigned binary shift, do i have any > options other than converting to a string using base_convert and
You could use BC: bcdiv($a, 2); to do $a >> 1; - Chris