def to_i(byte_endianness=:little_endian, bits_little_endian=false)
    i = 0
    bytes = convert_endianness(byte_endianness, :big_endian)
    bytes = bytes.reverse_byte_bits if bits_little_endian
    bytes.each_byte do |b|
      i <<= 8
      i |= b
    end
    i
  end
def to_i(byte_endianness=:little_endian, bits_little_endian=false)
    i = 0
    bytes = convert_endianness(byte_endianness, :big_endian)
    bytes = bytes.reverse_byte_bits if bits_little_endian
    bytes.each_byte do |b|
      i <<= 8
      i |= b
    end
    i
  end
Binary data is handled here in three representations:
  as an Integer
  as a byte sequence (String) (with specific endianness)
  an an hex-string (nibble values) (with specific endianness)
 Convert a byte string to an integer