Posted by Pedro Graca on 09/28/22 11:37
Pedro Graca wrote:
> yawnmoth wrote:
>> Why should >> even be concerned with whether or not integers are signed?
>
> ~$ php -r 'echo -8 >> 2, "\n";'
I forgot the rest of the post ...
Let's say -8 in binary is (ignore the spaces)
MSB == 10000000 00000000 00000000 00001000 == LSB
if you shift this right without concern for the sign, you get
MSB == 00100000 00000000 00000000 00000010 == LSB
which is 536870914
Do you think -8 >> 2 (-8 divided by 4) should equal 536870914? :)
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Navigation:
[Reply to this message]
|