# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  How 2 use right shift "<<"  and left shift ">>" operator in excel?

## v-2ajpau

How 2 use right shift "<<"  and left shift ">>" operator in excel?

----------


## Leith Ross

Hello v-2ajpau,

Excel doesn't have builtin left and right shift operators. You would need to construct a User Defined Funtion (UDF) in VBA . If you have a computer science background (I assume you do or you wouldn't post this question) you know what is involved in the binary math. I suspect if you search the web you find someone who has written the routines already.

Sincerely,
Leith Ross

----------


## Chip Pearson

VBA doesn't have any bit shift operators. You can replicate bit
shifts by multiplying or dividing by the appropriate power of 2.

Function ShiftLeft(Num As Long, Places As Integer) As Long
ShiftLeft = Num * (2 ^ Places)
End Function

Function ShiftRight(Num As Long, Places As Integer) As Long
ShiftRight = Num \ (2 ^ Places)
End Function

Note that there is no error checking in these procedures.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"v-2ajpau" <v-2ajpau@discussions.microsoft.com> wrote in message
news:13AFB30F-AA60-412C-86BB-FAD66D190E8D@microsoft.com...
> How 2 use right shift "<<"  and left shift ">>" operator in
> excel?

----------

