in reply to Mysteries of unpack

why does this printf("%d\n", unpack ("h", "F")); produce '6' on my system?
The unpack ("h", "F")); says 'Convert the letter capital-F into a hex-string, low byte first'. The hex for that letter is '46'. The low byte is '6'. You're printing an integer, and seeing it displayed.

Replies are listed 'Best First'.
Re^2: Mysteries of unpack
by ikegami (Patriarch) on Jun 17, 2009 at 14:41 UTC

    To get the desired result,

    >perl -e"printf(qq{%d\n}, unpack('C', pack('h', 'F')));" 15

    or

    >perl -le"print(hex('F'));" 15

    As you can see, the OP has pack and unpack backwards.