HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 5 Expressions

Bitwise Exclusive OR Operator

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

The bitwise exclusive OR operator (^) performs the bitwise exclusive OR function on its operands.

Syntax

exclusive-OR-expression ::=
AND-expression
exclusive-OR-expression ^ AND-expression

Description

The result of the binary operator ^ is the bitwise exclusive OR function of the two operands. Both operands must be integral types. The usual arithmetic conversions are performed on the operands. The type of the result is the converted type of the operands. The result is not an lvalue.

For each of the corresponding bits in the left operand, the right operand, and the result, the following table indicates the result of an exclusive OR operation.

Table 5-5 Exclusive OR Results

Bit in Left Operand

Bit in Right Operand

Bit in Result

0

0

0

0

1

1

1

0

1

1

1

0

 

You can use the exclusive OR operation for complementing bits. If a mask integer is exclusive OR'd with another integer, each bit position in the mask having a value of one will cause the corresponding position in the other operand to be complemented.

Example

var1 ^ var2