Rotate bits
aeklo
Posts: 20
I've been trying to figure out a simple method of rotating bits in Stamp Basic, but need some help...
Is there a function or simple way of doing a bit rotationof eg. a byte?
Something like:
B1 VAR Byte
B1 = %00000001
rot(B1) 'gives %10000000
rot(B1) 'gives %01000000
rot(B1) 'gives %00100000
etc.
/Anders
Is there a function or simple way of doing a bit rotationof eg. a byte?
Something like:
B1 VAR Byte
B1 = %00000001
rot(B1) 'gives %10000000
rot(B1) 'gives %01000000
rot(B1) 'gives %00100000
etc.
/Anders
Comments
B1 VAR Byte
B1 = %00000001
B1 = B1<< 7
B1 = B1 >> 1
B1 = B1 >> 1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Rotate_Left:
··DO WHILE (idx > 0)
····carry = temp.BIT7
··· temp = temp << 1
··· temp.BIT0·= carry
··· idx = idx - 1
· LOOP
· RETURN
Rotate_Right:
··DO WHILE (idx > 0)
····carry = temp.BIT0
··· temp = temp·>> 1
··· temp.BIT7·= carry
··· idx = idx - 1
· LOOP
· RETURN
In·either case, temp gets rotated, carry is a bit-variable for·storage, and idx is the number of positions to rotate.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
/Anders