|
Posted by Jerry Stuckle on 09/27/36 11:37
yawnmoth wrote:
> Palle Hansen wrote:
>
>>yawnmoth wrote:
>>
>>>Using >> normally shifts bits to the right x number of times, where x
>>>is specified by the programmer. As an example, 0x40000000 >> 8 yields
>>>0x00400000. This makes me wonder... why doesn't the same thing happen
>>>with 0x80000000 >> 8? The number it yields is 0xff800000 - not
>>>0x00800000. The following script better demonstrates this:
>>>
>>><?
>>>echo sprintf('%08x',0x40000000 >> 8)."\n";
>>>echo sprintf('%08x',0x80000000 >> 8);
>>>?>
>>>
>>>Anyway, any ideas?
>>
>>My guess is that PHP sees 0x8000000 as a *signed* integer
>
>
> Why should >> even be concerned with whether or not integers are signed?
>
Well, it's got to make a decision one way or the other. As a signed
integer, 0x80000000 is -2,147,483,648. Shift right one bit and you get
0xc0000000, which is 1,073,741,824 - the correct result for dividing by 2.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|