Shop OBEX P1 Docs P2 Docs Learn Events
Rotate on Byte? Or always a long — Parallax Forums

Rotate on Byte? Or always a long

TJHJTJHJ Posts: 243
edited 2009-04-06 18:43 in Propeller 1
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?

Ex
Var
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.

Thanks
·TJ

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-06 18:37
    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)
  • mctriviamctrivia Posts: 3,772
    edited 2009-04-06 18:37
    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 has crystal, eeprom, and programing header in a 40 pin dip 0.7" pitch module with uSD reader, and RTC options.
  • virtuPICvirtuPIC Posts: 193
    edited 2009-04-06 18:43
    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 for tools & toys
Sign In or Register to comment.