- harmonv
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)mod256)or(x>127)endfunctionfunction rotright(x)
rotright =(128*(x and1))orint(x/2)endfunction
Bit Shift Functions
-Table of Contents
This is really easy to do:
Shift Left
Shift Right
Remove High Bit
If you want to remove the high bit when shifting left, just write a function for that, like so:Get the idea? :)
-Carl
-
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.