bitxor

Bit-wise exclusive OR of integers.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

C = bitxor(A, B)

Bit-wise XOR of the binary representations of A and B.

Description

Each bit of the result is 1 when the corresponding bits of the operands differ. XOR with the same mask twice restores the original value, which makes it useful for toggling bits and for simple checksums.

bitxor(x, x) is always 0.

Input arguments

A, B
Arrays of nonnegative integers (doubles must be integer-valued, up to 2^53) or integer types of the same class. Sizes must be compatible.

Output arguments

C
Array with the combined bits, of the same class as the inputs.

Example

bitxor(12, 10)
bitxor(uint8(255), uint8(15))
bitxor(bitxor(9, 5), 5)
Output
ans = 6
ans = uint8
   240
ans = 9

See also

bitand bitor xor bitcmp dec2bin