What is the meaning of the << Operator in Visual Basic? I'm re-writing some sample code that contains (result << 4). The code sample is in VB.Net. I'm rewriting it in VBA for MS Access. Any help would be appreciated.
Mike TomlinsonMiddle School Assistant TeacherCommented:
<< is the left shift operator. It will shifts the bits of a number to the left by the specified number of bits. Here is an example from the help file:
Dim Pattern As Short = 192 ' Bit pattern is 0000 0000 1100 0000.
Dim Result1, Result2, Result3, Result4, Result5 As Short
Result1 = Pattern << 0 ' Result is 192 (0000 0000 1100 0000).
Result2 = Pattern << 4 ' Result is 3072 (0000 1100 0000 0000).
Result3 = Pattern << 9 ' Result is -32768 (1000 0000 0000 0000).
Result4 = Pattern << 17 ' Result is 384 (0000 0001 1000 0000).
Result5 = Pattern << -1 ' Result is 0 (shifted 15 places to left).
since a<<LeftShift has the effect of multiplying the value of a by 2 raised to the LeftShift power, then the VBA equivalent of the Shift Left operator is to MULTIPLY the original value by 2^LeftShift
A<<4 is (in VBA) A = A * 2^4 the ^ is the exponentiation operator so 2^4 is 2 raised to the power 4
result << 4 means bit shift result left 4 bits.
Each left shift operation is like multiplying the result by 2, so shifting 4 bits is like multiplying by 2^4 (16)
In VBA you could multiply your number by 16, but you will have to watch out for overflow errors.
Bitwise Left Shift and Right Shift for VB
http://www.freevbcode.com/ShowCode.asp?ID=2045