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

x
  • 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.
0
TimSledge
Asked:
TimSledge
1 Solution
 
Erick37Commented:
<< 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
http://www.freevbcode.com/ShowCode.asp?ID=2045
0
 
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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/vblrfvbspec11_5a.asp

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:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10122746.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20172935.html
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20151207.html

~IM
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Good afternoon Erick37...

=)
0
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
LOL...we both posted at the same time.  If I had just clicked a little sooner...


;)
0
 
Erick37Commented:
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.

0
 
Arthur_WoodCommented:
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

AW
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Erick37,

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.

~IM
0

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