[Gambas-user] Rol/Ror vs. Shl/Shr
Benoit Minisini
gambas at ...2...
Thu Jun 12 20:27:55 CEST 2003
Le Jeudi 12 Juin 2003 04:08, Rob a écrit :
> I was trying to come up with some examples for Rol/Ror tonight (bit rotate
> left/bit rotate right) and an explanation for the differences from Shl/Shr,
> so I made a simple console only project and put this in sub main:
>
> DIM oldvar AS Byte
> DIM newvar AS Byte
>
> oldvar = 129
> newvar = Shl(oldvar,1)
> PRINT newvar
>
> newvar = Rol(oldvar,1)
> PRINT newvar
>
> and built and ran it, and got this:
>
> 2
> 2
>
> meaning Shl and Rol both treat carried bits the same (discard them). Are
> they meant to just be aliases of each other or is this a gambas bug?
>
> For what it's worth, changing them to Shr and Ror returned
> 64
> 64
> which is consistent, but when I made newvar an Integer, it returned
> 64
> -2147483584
> which is more what I'd expect (the latter being the output of Ror.) I
> noticed there were no examples for Rol/Ror in the encyclopaedia and figured
> maybe it was something Benoit meant to fix a long time ago and got
> distracted by more interesting things ;)
>
> Rob
>
Hum... In fact these functions work only with full integers, because they
don't manage the case where their arguments are less than 4 bytes integers.
Call this a bug !
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list