<p>Can someone explain why how the result for the following unpack is computed?</p>

<pre><code>"aaa".unpack('h2H2')               #=&gt; ["16", "61"]
</code></pre>

<p>In binary, 'a' = 0110 0001.  I'm not sure how the 'h2' can become 16 (0001 0000) or 'H2' can become 61 (0011 1101).</p>

Check out the Programming Ruby
reference
on unpack. Here's a snippet:
Decodes str (which may contain binary
data) according to the format string,
returning an array of each value
extracted. The format string consists
of a sequence of single-character
directives, summarized in Table 22.8
on page 379. Each directive may be
followed by a number, indicating the
number of times to repeat with this
directive. An asterisk ("*") will
use up all remaining elements. The
directives sSiIlL may each be followed
by an underscore ("_") to use the
underlying platform's native size for
the specified type; otherwise, it uses
a platform-independent consistent
size. Spaces are ignored in the format
string. See also  Array#pack   on page
286.
And the relevant characters from your example:
H     Extract hex nibbles from each character (most significant first).
h     Extract hex nibbles from each character (least significant first).