Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

<< Operator in Visual Basic

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.
1 Solution
<< and >> are bit shift operators.

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
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).

Here is the online documentation:

As far as I know there are no bit shifting operators or functions available in MS Access.  Here are some VB6 examples on how to accomplish this via code:

Mike TomlinsonMiddle School Assistant TeacherCommented:
Good afternoon Erick37...

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

TimSledgeAuthor Commented:
Thanks to both of you for your help.
Mike TomlinsonMiddle School Assistant TeacherCommented:
LOL...we both posted at the same time.  If I had just clicked a little sooner...

Hi IM,

Sorry to invade your topic area, but it seems that MS has dumped all us VB6 and VBA users.  I quess I'll spend more time in here with the "in" crowd.

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

Mike TomlinsonMiddle School Assistant TeacherCommented:

I'm always glad to see more "real" experts in any TA.   =)

It's not my Topic Area anyways, RonaldBiemans is the current king, but he doesn't comment in the VB6 area like I do.


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now