Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Integer#^

self ^ other → integer

Bitwise EXCLUSIVE OR; each bit in the result is 1 if the corresponding bits in self and other are different, 0 otherwise:

Example
"%04b" % (0b0101 ^ 0b0110) # => "0011"

Raises an exception if other is not an Integer.

Related: Integer#& (bitwise AND), Integer#| (bitwise OR).

See also #[] #| #>> #~ also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0