View Full Version : Rotate on Byte? Or always a long

04-07-2009, 01:33 AM
Hey all,
Dumb question. If I use the rotate command on a byte, will it properly rotate around to the 8th bit? Or Does rotate like its a long?


byte RotateTest

Pub Main

RotateTest := %1010
RotateTest <-= 8
'Is rotate test now %0000_1010 or %1010_0000_0000 ???

Side note

Anyone have a good way to rotate a 4 bit value around? With out a bunch of checking?

Im really trying to rotate %1100 right 1 per loop. But keep it all in the 4 bit format.


I owe everyone here a bunch, So thanks again for answering my dumb questions.
Projects. RG500 ECU system. PropCopter. Prop CanSat. Prop Paste Gun.
Suzuki RG500 in a RGV 250 frame.
Bimota V-Due (Running on the fuel injection system)
Aprilia RS250

Mike Green
04-07-2009, 01:37 AM
All arithmetic operations work on 32-bit values.

To rotate a 4 bit value, you have to do masking and multiple shifts like

(value << 1 & %1110) | (value >> 3 & %0001)

04-07-2009, 01:37 AM
if you are rotating 4 bit 1 you need

rotate it then do if greater then 16 subtract 15 this will clear the greater bit and set lowest bit at same time

Need to make your prop design easier or secure? Get a PropMod (http://propmodule.com) has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.

04-07-2009, 01:43 AM
Mike, if you know that all other (all insignificant) bits are 0 you can reduce to one post-shift mask. Your 4 bit example reduces to:

((value << 1) | (value >> 3)) & %1111

Airspace V - international hangar flying!
www.airspace-v.com/ggadgets (http://www.airspace-v.com/ggadgets) for tools & toys