Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Integer#&

self & other → integer

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

Example
"%04b" % (0b0101 & 0b0110) # => "0100"

Raises an exception if other is not an Integer.

Related: Integer#| (bitwise OR), Integer#^ (bitwise EXCLUSIVE OR).

See also #% #* .try_convert #** also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0