Older Version Newer Version

Alyce Alyce Oct 5, 2006

=Bit Shift Functions= [[user:CarlGundel]] [[toc]] This is really easy to do: ==Shift Left== [[code format="vbnet"]] function shiftLeft(bitsValue) shiftLeft = bitsValue * 2 end function [[code]] ==Shift Right== [[code format="vbnet"]] function shiftRight(bitsValue) shiftRight = int(bitsValue / 2) end function [[code]] ==Remove High Bit== If you want to remove the high bit when shifting left, just write a function for that, like so: [[code format="vbnet"]] function shiftByteLeft(bitsValue) shiftByteLeft = 255 and (bitsValue * 2) end function [[code]] Get the idea? :) -Carl [[user:CarlGundel]] ==Ring Shifts== [[user: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. [[code format="vbnet"]] 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 [[code]] Get the idea? :) -Carl [[user:CarlGundel]]