Ruby/Number/Binary number
Материал из Wiki.crossplatform.ru
Содержание |
1 || 2 && nil
puts 1 || 2 && nil # => 1
Binary bit shift left and right
(0b1011 << 1).to_s(2) # => "10110" 11 << 1 => 22 (0b10110 >> 2).to_s(2) # => "101" 22 >> 2 => 5
Binary number with 0b
puts 0b100 # => 4
Bit and, or
(0b1010 & 0b1100).to_s(2) # => "1000" (0b1010 | 0b1100).to_s(2) # => "1110" (0b1010 ^ 0b1100).to_s(2) # => "110"