This article applies to:
This item was introduced in E-Prime 2.0 (126.96.36.199).
This feature provides for manipulating numeric values in E-Basic through bitwise operations. Due to restrictions of the E-Basic language, precision loss may be incurred if attempting bitwise acts via the '*', '/', 'AND', 'OR', or 'XOR' operators. Consider mitigating this with the following functions:
LShift([value], [number of bits to shift left])
RShift([value], [number of bits to shift right])
For further information on scripting using E-Basic, please refer to the E-Prime Command Reference (https://pstnet.com/ecr).
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.
Please sign in to leave a comment.