I tested following code wit开发者_JS百科h ruby 1.9.2 .
"hello".unpack('H*')
=> ["68656c6c6f"]
> "hello".unpack('h*')
=> ["8656c6c6f6"]
Why the result of h*
is off by 1. Also I thought nibble is 4 bits. However 68
, 65
, 6c
, 6c
and 6f
are all taking one byte.
The difference between h* and H* is the order they write the halves of the byte (nibbles). h
writes lower half byte first and H
writes the higher half byte first.
And yes, nibble is half of the byte - that is 4 bits.
You can check out with detailed usage of pack/unpack in this post
精彩评论