harmonv
Oct 5, 2006
Bit Shift Functions
-This is really easy to do:
Shift Left
function shiftLeft(bitsValue)
shiftLeft = bitsValue * 2
end function
Shift Right
function shiftRight(bitsValue)
shiftRight = int(bitsValue / 2)
end function
Remove High Bit
If you want to remove the high bit when shifting left, just write a function for that, like so:function shiftByteLeft(bitsValue)
shiftByteLeft = 255 and (bitsValue * 2)
end function
Ring Shifts
Sometimes you want to rotate bits (ie:taking the bit that falls off one end and sticking it on the other.)Here are routines to rotate the bits in an 8-bit number.
function rotleft(x)
rotleft = ((x+x) mod 256) or (x>127)
end function
function rotright(x)
rotright = (128*(x and 1)) or int(x/2)
end function
Get the idea? :)
-Carl
-