Module: SJCL::Codec::Hex
- Defined in:
- lib/sjcl/codec_hex.rb
Class Method Summary collapse
Class Method Details
.fromBits(arr) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/sjcl/codec_hex.rb', line 3 def self.fromBits(arr) out = "" arr.length.times do |i| out += ((arr[i] & 0xFFFFFFFF)|0).to_s(16).rjust(8,'0')[0,8] end return out[0, SJCL::BitArray.bitLength(arr)/4] end |
.toBits(str) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sjcl/codec_hex.rb', line 11 def self.toBits(str) out = [] len = str.length str = str + "00000000" i = 0 while i < str.length out.push(str[i,8].to_i(16) ^ 0) i += 8 end return SJCL::BitArray.clamp(out, len*4) end |