It is very slow, try this. The following works for values> = 0, but will throw the array index out of bounds for bit-bits> 14 bits, and the code:
dim ShiftArray ShiftArray = Array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024,2048,4096, 8192, 16384) ' example usage dim num num = 17 num = num * ShiftArray(2) ' left shift 2 bits num = num / ShiftArray(3) ' right shift 3 bits
Multiply the number of bits by a shift to shift left. Divide to shift to the right. This array works for 16-bit integers.
For 32-bit integers, the array will exit the array's string index for bit-bits> 30 and is equal to:
dim ShiftArray ShiftArray = Array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824)