Module: Preservation::Conversion
- Defined in:
- lib/preservation/conversion.rb
Overview
Conversion
Class Method Summary collapse
-
.bin_to_hex(s) ⇒ Hexadecimal String
Binary to hexadecimal.
-
.hex_to_bin(s) ⇒ Binary String
Hexadecimal to binary.
Class Method Details
.bin_to_hex(s) ⇒ Hexadecimal String
Binary to hexadecimal
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
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 |