Bitwise Operator Support

Standard PowerBuilder applications allow the use of the logical operators AND, OR, and NOT to evaluate boolean expressions. In .NET applications and components, in addition to evaluating boolean expressions, you can use these same operators to perform bitwise evaluations.

For the AND and OR operators, a bitwise evaluation compares the bits of one operand with the bits of a second operand. For the NOT operator, a bitwise evaluation assigns the complementary bit of the single operand to a result bit.

The operands in a bitwise comparison must have integral data types, such as integer, uint, long, ulong, and longlong. However, if either of the operands (or the sole operand in the case of a NOT operation) has an any datatype, the .NET application or component treats the operation as a standard logical evaluation rather than as a bitwise comparison.

You can perform a bitwise comparison only inside a .NET conditional compilation block. If you try to evaluate operands with integral datatypes in a standard PowerBuilder application, you will get a compiler error.

For .NET applications and components, you can also use the bitwise operator XOR. If you use this operator to evaluate a boolean expression in the .NET environment, the return result is true only when one of the operands is true and the other is false. If both operands are true, or both are false, the return result for the XOR operator is false.

This table describes the result of using the bitwise operators:

Bitwise operators in the .NET environment

Operator

Description

AND

The bitwise “AND” operator compares each bit of its first operand to the corresponding bit of its second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

OR

The bitwise “inclusive OR” operator compares each bit of its first operand to the corresponding bit of its second operand. If either bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

XOR

The bitwise “exclusive OR” operator compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

NOT

This is a unary operator. It produces the bitwise complement of its sole operand. If one bit is 1, the corresponding result bit is set to 0. Otherwise, the corresponding result bit is set to 1.