BitRight and BitLeft Operator Support

PowerBuilder 12 includes support for bitwise right-shift and left-shift operators.

BitRight operator

The right-shift operator shifts the first operand to the right by the number of bits specified in the second operand. This works the same as the C# “>>” operator.

The shift to the right can be arithmetic or logical, depending on the datatype of the first operand:
  • Arithmetic – if the first operand is an signed integral datatype, high-order empty bits are set to the sign bit.
  • Logical – if the first operand is an unsigned integral datatype, high-order bits are filled with zeros.

BitLeft operator

The left-shift operator shifts the first operand to the left by the number of bits specified in the second operand. This works the same as the C# “<<” operator.

The high-order bits of the first operand are discarded and the low-order empty bits are filled with zeros. Shift operations never cause overflows. The shift amount to the left depends on the bit quantity of the first operand datatype. For example:
  • 32-bit quantity – if the first operand is a long or ulong datatype, the shift amount is given by the low-order five bits of the second operand. The maximum left shift is 0x1f, or 31 bits.
  • 64-bit quantity – if the first operand is a longlong or ulonglong datatype, the shift amount is given by the low-order six bits of the second operand. The maximum left shift is 0x3f, or 63 bits.

Operator precedence

Bitwise shift operations are performed before relational (=, >, <, <=, >=, <>), negation (NOT), and logical (AND, OR) operations. They are performed after grouping, unary, exponentiation, arithmetic (multiplication, division, addition, subtraction), and string concatenation operations.