The bitwise AND operation allows multiplying the bits of numbers and returning the result in decimal format. To achieve this, we must use the operator &
. This means that when we perform a bitwise AND operation on two numbers, say 2
and 1
, this is what will happen:
2
and 1
will be multiplied. 0010 * 0001 = 0000
0000
is equivalent to 0
. Hence, 2 & 1
is equal to 0
.number1 & number2
number1
and number2
: These are the numbers we want to get the decimal equivalent of multiplying their binaries.
The value returned is the decimal equivalent of the result returned by multiplying the bits of numbers number1
and number2
.
puts 2 & 1puts 7 & 5puts 10 & 3puts 200 & 5
In the code above: