I am using ruby 1.9.2 and this is what I found.
> ['A'].pack('H')
=> "\xA0"
Since H takes high nibble first and since the input A is only one nibble the additional nibble should be padded at the front. Which means the above code should be same as
> ['0A'].pack('H')
But it seems I am missing something. Anyone cares to explain.
Since the answer of the first case is \xA0 it is clear that the zero is being padded to the right. However when we are dealing with high nibble first then A should be same as 0A .
If you pack half a byte, one nibble, that’s what you’ll get. You need to specify how long your input string is in nibbles:
To
packis to do the opposite ofunpack, so don’t omit the length argument.