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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -