class Array
Public Instance Methods
bytes_to_bin()
click to toggle source
# File lib/common.rb, line 11 def bytes_to_bin raise "Not a byte array" unless self.is_byte_array? '0b' + self.map { |b| b.to_s(2).rjust(8, '0') }.join end
bytes_to_hex()
click to toggle source
# File lib/common.rb, line 6 def bytes_to_hex raise "Not a byte array" unless self.is_byte_array? '0x' + self.map { |b| b.to_s(16).rjust(2, '0') }.join end
bytes_to_utf8()
click to toggle source
# File lib/common.rb, line 21 def bytes_to_utf8 raise "Not a byte array" unless self.is_byte_array? self.pack('C*').force_encoding('utf-8') end
is_byte_array?()
click to toggle source
# File lib/common.rb, line 26 def is_byte_array? self.all? {|e| e >= 0 and e <= 255 } end