[Gambas-user] Rol/Ror vs. Shl/Shr

Rob sourceforge-raindog2 at ...94...
Thu Jun 12 04:08:04 CEST 2003

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:


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
which is consistent, but when I made newvar an Integer, it returned
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 ;)


More information about the User mailing list