Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ttcrypt.rb

Instance Method Summary collapse

Instance Method Details

#bytes_to_integer(order: :BE) ⇒ Symbol

Convert string that is supposed to be binary data to integer value using specified bytes order

Returns:

  • (Symbol)

    either :BE or :LE



31
32
33
34
35
36
37
38
# File 'lib/ttcrypt.rb', line 31

def bytes_to_integer order: :BE
  order == :BE || order == :LE or raise ArgimentError, "unkown order, should be either :BE or :LE"
  result = 0
  (order == :BE ? self.bytes : self.bytes.reverse).each { |b|
    result = (result << 8) | b.ord
  }
  result
end