Bitwise AND Operator
The bitwise AND operator (&
) is used to perform a bitwise AND operation on two numbers.
Not what you're looking for? The &
symbol is used in several syntactically distinct ways in Ruby. Head over to the Ampersand page to get a lay of the land.
Here is an example of using the bitwise AND operator.
10 & 3 # => 2
> 10.to_s(2)
=> "1010"
> 3.to_s(2)
=> "11"
> (10 & 3).to_s(2)
=> "10"
> 0b10.to_i
=> 2