ruby - In case of high nibble first zero should be added first -
i using ruby 1.9.2 , found.
> ['a'].pack('h') => "\xa0" since h takes high nibble first , since input a 1 nibble additional nibble should padded @ front. means above code should same as
> ['0a'].pack('h') but seems missing something. cares explain.
since answer of first case \xa0 clear 0 being padded right. when dealing high nibble first a should same 0a .
if pack half byte, 1 nibble, that's you'll get. need specify how long input string in nibbles:
'x'.unpack('h') # => ["8"] 'x'.unpack('h2') # => ["85"] 'x'.unpack('h') # => ["5"] 'x'.unpack('h2') # => ["58"] to pack opposite of unpack, don't omit length argument.
Comments
Post a Comment