pack & unpack

http://blog.bigbinary.com/2011/07/20/ruby-pack-unpack.html

http://www.blackbytes.info/2017/01/read-binary-data/?tl_inbound=1&tl_target_all=1&tl_form_type=1&tl_period_type=1

unpack = String#unpack

Endian = 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

pack = read the stored data.

Binary File Parsing

or parse image

Last updated

Was this helpful?