|
Posted by Oli Filth on 01/20/06 17:03
Jerry Stuckle said the following on 20/01/2006 13:22:
> Oli Filth wrote:
>> Tim Roberts said the following on 20/01/2006 06:59:
>>
>>> "Chung Leong" <chernyshevsky@hotmail.com> wrote:
>>>
>>>> How is -4,738,698,913 ^ 43814 = -443,704,711 correct?
>>>
>>>
>>> First, answer this question: how can you squeeze -4,738,698,913 into a
>>> 32-bit variable?
>>>
>>> 4,738,698,913 would be 1_1A72_CEA1 in hex, but that needs 33 bits.
>>> If you
>>> truncate that to 32 bits, you get 1A72_CEA1. Xor that with 43,814,
>>> which
>>> is AB26 in hex, and you get 1A72_6587, which just happens to be
>>> 443,704,711.
>>
>>
>> But that's assuming that PHP performs XOR on the absolute values of
>> the operands, and then negates appropriately. i.e.:
>>
>> (-4,738,698,913 ^ 43,814) == -(4,738,698,913 ^ 43,814)
>>
>> which isn't the case, at least not always. e.g.:
>>
>> echo (3 ^ 7) . "\n";
>> echo (-3 ^ 7) . "\n";
>>
>> i.e. doing XOR directly on the 2's-complement representations of the
>> operands.
>>
>
> No, Tim is correct. PHP CAN'T do an XOR on -4,738,698,913 on a 32 bit
> system. The value doesn't fit into 32 bits!
I'm aware of that.
However, I now realise that -443,704,711 is the correct answer! Made a
mistake in my paper calculations! Apologies...
--
Oli
Navigation:
[Reply to this message]
|