HP C A.06.05 Reference Manual

Expressions and Operators
Bit Operators (<<, >>, &, ^, |, ~)
Chapter 596
Bitwise exclusive OR (^) The bitwise exclusive OR operator performs logical operations
on a bit-by-bit level using the following truth table:
The bitwise exclusive OR (XOR) operator (^) sets a bit in the resulting value's bit position if
either operand (but not both) has a bit set at the position.
Bitwise Complement (~) The bitwise complement operator (~) performs logical operations
on a bit-by-bit level using the following truth table:
The bitwise complement operator (~) reverses each bit in the operand:
Table 5-5 Truth Table for the exclusive OR, ^
bit x of op1 bit x of op2 bit x of result
000
011
101
110
Table 5-6 Example Using the XOR Operator
Expression Hexadecimal Value Binary Representation
9430
5722
0x24D6
0x165A
00100100 11010110
00010110 01011010
9430 ^ 5722 0x328C 00110010 10001100
Table 5-7 Truth table for the ~, Bitwise Complement
bit x of op2 result
00
01
Table 5-8 Example Using the Bitwise Complement Operator
Expression Hexadecimal Value Binary Representation
9430 0x24d6 00100100 11010110