← Back to Ruby Operators

Bitwise Exclusive OR Operator

The bitwise exclusive OR operator (^) is used to perform a bitwise exclusive OR operation on two numbers. This is not to be confused with the bitwise OR operator.

10 ^ 3 # => 9

> 10.to_s(2)
=> "1010"
> 3.to_s(2)
=> "11"
> (10 ^ 3).to_s(2)
=> "1001"
> 0b1001.to_i
=> 9

Note: this symbol is often generally referred to as the caret symbol though it wouldn't make sense to call it that in this context.

Resources