E-BASIC: Bitwise operations in E-Basic (LShift, RShift, BitwiseAnd) [18531]

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request
Return to top


1 comment

  • Avatar
    David McFarlane

    EP2 also includes the following bitwise functions:


    which work as expected.

    Note that LShift may produce an overflow error under some conditions.  E.g.,

    Dim  x0 As Integer, x1 As Integer
    x0 = &h4000
    x1 = LShift( x0, 1 )

    will produce an overflow error (instead of the expected &h8000) because the LShift operation here produces a Long value.  You may avoid that in a couple of ways:

    Dim  xLng As Long
    xLng = LShift( x0, 1 )

    this will simply produce the Long value, fine as long as that works for your application;

    x1 = LShift( BitwiseAnd(x0, &h3FFF), 1) Or IIf( (x0 < &h4000), 0, &h8000)

    this is a kludge that I came up with; or,

    x1 = CInt("&h" & Hex(LShift(x0, 1)))

    due to David Nicholson at PST Support, which I like better.

    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk