<< Operator in Visual Basic

Posted on 2005-04-02
Medium Priority
Last Modified: 2012-08-14
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.
Question by:TimSledge
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 32

Accepted Solution

Erick37 earned 1000 total points
ID: 13689385
<< 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
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13689387
<< 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:

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13689389
Good afternoon Erick37...

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 13689407
Thanks to both of you for your help.
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13689411
LOL...we both posted at the same time.  If I had just clicked a little sooner...

LVL 32

Expert Comment

ID: 13689423
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.

LVL 44

Expert Comment

ID: 13689442
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

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13689528

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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question