Wednesday 15 February 2012

decoding - ruby pack and hex values -


There is a blunt four bits, this means that 16 (2 ^ 4) are possible values, that means that a hibel is a hex The number corresponds to the number, because the hex is the base 16. A byte is 2 ^ 8, so 2 hex digits can be represented, and as a result 2 nibbles

is a 1 byte character:

'A'

that character is 2 ^ 8:

  'A' .unpack ('B *') = & gt; ["01000001"]   

This means that it should represent two hex digits:

  01000001 == 41   

According to the ruby ​​documentation, for the Array method pack, when aTemplateString (parameter) is equal to 'H', it will return a hex string. But this is what I get back to:

  ['A']. Pack ('H') = & gt; "\ XA0"   

My first issue is that it should not be hex value. It should have withdrawn the hex value of 41. The second point is the concept of nuisance, as I mentioned above, for 1 byte it means, it should return two nibbles. But it puts a 0 above it, because it thinks that only 1 fall in the input, even though 'A' is a byte and two nuns, so I am missing something.

I think you want:

  'A' . Unpack ('H *') # = & gt; ["41"]   

The opposite is:

  ['41']. Pack ('H *') # = & gt; "A"    

No comments:

Post a Comment