Bitwise Class
Performs bitwise operations on integers.
More information available in parent classes: Object
Notes
The BitwiseAnd, BitwiseOr, and BitwiseXor functions are obsolete. Use the corresponding methods of the Bitwise class.
You do not need to create an instance of the Bitwise class in order to access its methods. It's a special object, like System or Application, that always exists.
The BitAnd method returns an Integer that is the result of comparing each bit of the two integers passed (or contiguous integers passed if passing three or more integers) and assigning 1 to the bit position in the integer returned if both bits in the same position in the integers passed are 1. Otherwise, 0 is assigned to the bit position.
The BitOr method returns an Integer that is the result of comparing each bit of the two integers passed (or contiguous integers passed if passing three or more integers) and assigning 1 to the bit position in the integer returned if either of the bits in the same position in the integers passed are 1. Otherwise, 0 is assigned to the bit position.
The BitXor method returns an Integer that is the result of comparing each bit of the two integers passed (or contiguous integers passed if passing three or more integers) and assigning 1 to the bit position in the integer returned if both bits in the same position in the integers passed are not equal. Otherwise, 0 is assigned to the bit position.
Ones complement is sometimes used to represent positive and negative numbers. Positive numbers start with zeros and negative numbers start with ones. The only problem is that zero is represented two ways
Decimal | Ones complement | Signed Decimal |
0 | 000 | 0 |
1 | 001 | 1 |
2 | 010 | 2 |
3 | 011 | 3 |
√ | 100 | -3 |
5 | 101 | -2 |
6 | 110 | -1 |
7 | 111 | -0 |
Example
i=Bitwise .bitand(5,3) //returns 1
i=Bitwise.bitor(5,3) //returns 7
i=Bitwise.bitxor(5,3) //returns 6
The following example illustrates how to re-express a bit expression that was written in C in REALbasic. The following expression in C:
(0xE0 | ((c >> 12) & 0x0F))
would become: