pack & unpack
http://blog.bigbinary.com/2011/07/20/ruby-pack-unpack.html
unpack = String#unpack
String#unpackEndian = Byte Order
MSB, LSB = bit order
1 byte = 2 nibbles = 8bits
bit
C Ascii = 67 (2^0 + 2^1 + 2^6)
'C'.unpack('b*') # LSB
# => ["11000010"]
'C'.unpack('B*') # MSB
# => ["01000011"]String to ASCII Values
C* = 8-bit unsigned integer
"hello".unpack('C*')
=> [104, 101, 108, 108, 111]hex
104.to_s 16 = hex value of the string.
You can also do
count
pack = Array#pack
Array#packpack = read the stored data.
Binary File Parsing
or parse image
Last updated
Was this helpful?