In Ruby, the bitwise left shift operator shifts each bit of a number to the left by n positions.
For a better understanding, see the diagram below:
number << shifts
number: This is the number whose bits we want to shift.
shifts: This is the number of positions we want to shift the bits of number.
The value returned is an integer. It is equivalent to the decimal value of the number after shifting the bits.
# shift some bits of numbersputs 2 << 1puts 7 << 2puts 1 << 2puts 5 << 3
In the code above: