Binary bit shift left and right : Binary number « Number « Ruby






Binary bit shift left and right


(0b1011 << 1).to_s(2)   # => "10110"   11 << 1 => 22
(0b10110 >> 2).to_s(2)  # => "101"     22 >> 2 => 5

 








Related examples in the same category

1.Binary number with 0b
2.Bit and, or
3.1 || 2 && nil