Module: Binary::Utils
- Defined in:
- lib/binary/utils.rb,
lib/binary/utils/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.as_binary(string) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/binary/utils.rb', line 14 def as_binary(string) string = string.to_s if string.respond_to?(:force_encoding) string.force_encoding('ASCII-8BIT') else string end end |
.bin_to_hex(string) ⇒ Object
10 11 12 |
# File 'lib/binary/utils.rb', line 10 def bin_to_hex(string) as_binary(string).unpack('H*').first end |
.hex_to_bin(string) ⇒ Object
6 7 8 |
# File 'lib/binary/utils.rb', line 6 def hex_to_bin(string) as_binary( [string].pack('H*') ) end |