Module: Preservation::Conversion

Defined in:
lib/preservation/conversion.rb

Overview

Conversion

Class Method Summary collapse

Class Method Details

.bin_to_hex(s) ⇒ Hexadecimal String

Binary to hexadecimal

Parameters:

  • s (Binary String)

Returns:

  • (Hexadecimal String)


10
11
12
# File 'lib/preservation/conversion.rb', line 10

def self.bin_to_hex(s)
  s.each_byte.map { |b| b.to_s(16) }.join
end

.hex_to_bin(s) ⇒ Binary String

Hexadecimal to binary

Parameters:

  • s (Hexadecimal String)

Returns:

  • (Binary String)


18
19
20
# File 'lib/preservation/conversion.rb', line 18

def self.hex_to_bin(s)
  s.scan(/../).map { |x| x.hex.chr }.join
end