Shifting bits in a byte

BlitzMax Forums/BlitzMax Beginners Area/Shifting bits in a byte

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Thanks AD, I'll have a look at that later.

Somewhat better than the awful, awful hack that I came up with:

Local b:Byte=2
Local nb:Byte

shift=2

For i=0 To 7
	If (b & Int(Ceil(2^i))) nb :| Int(Ceil(2^(wrapBit(i,shift))))
Next

Print Bin(b)
Print Bin(nb)

Function wrapBit(bitIndex,bitShift)
	bitIndex :+ bitShift
	If bitIndex > 7 bitIndex = (bitIndex-8)
	Return bitIndex
End Function 


Ahem.