GMP Bit shift doesn't work on negative numbers
问题 I found this function at php.net. It seems to work on positive numbers, but fails on negative ones: function gmp_shiftr($x,$n) { // shift right return(gmp_div($x,gmp_pow(2,$n))); } echo -1 >> 8; //returns -1, presumably correctly echo "<br />"; echo gmp_strval(gmp_shiftr(-1,8)); //returns 0, presumably incorrectly How could I fix up the function to work with negatives? Two ideas I have: Maybe I could do something along the lines of if (whatever) { $a >> $b} else{ gmp_shiftr($a, $b) }? Or,