Module: Base16

Defined in:
lib/base16.rb,
lib/base16/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.decode16(what) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/base16.rb', line 6

def decode16(what)
  chars = ''
  ret = ''
  what.each_char do |c|
    chars += c
    if chars.size == 2
      ret += chars.to_i(16).chr
      chars = ''
    end
  end
  ret
end

.encode16(what) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/base16.rb', line 19

def encode16(what)
  ret = ''
  what.each_char do |c|
    ch = c.ord.to_s(16)
    if ch.size == 1
      ch = '0' + ch
    end
    ret += ch
  end
  ret.upcase
end