[Gambas-user] Bit manipulation functions
Jussi Lahtinen
jussi.lahtinen at ...626...
Sat Nov 20 16:58:07 CET 2010
Argh... no.
Try this:
? bin(Lsr(-9,1),32)
01111111111111111111111111111011
Jussi
On Sat, Nov 20, 2010 at 17:55, Jussi Lahtinen <jussi.lahtinen at ...626...>wrote:
>
> PRINT "Bin(-9) :"; Bin(-9)
>> PRINT "Bin(Lsl(-9, 1)):"; Bin(Lsl(-9, 1))
>> PRINT "Bin(Lsr(-9, 1)):"; Bin(Lsr(-9, 1))
>>
>> Bin(-9)
>> :1111111111111111111111111111111111111111111111111111111111110111
>>
>> Bin(Lsl(-9,1)):1111111111111111111111111111111111111111111111111111111111101110
>> Bin(Lsr(-9,1)):1111111111111111111111111111011
>>
>> Lsl is correct, it adds a 0 at the right and shift binary to left
>> Lsr i think is wrong
>>
>> -9 is
>> 1111111111111111111111111111111111111111111111111111111111110111
>>
>> Lsr(-9,1) should be
>> 0111111111111111111111111111111111111111111111111111111111111011
>>
>>
> I think the sign bit shouldn't be shifted. So this is correct.
>
> Jussi
>
>
More information about the User
mailing list