Instead of
sprintf "%1x", $var;
use
sprintf "%2x", $var;
This will give two nybbles (a full byte) so pack and unpack give the expected answer.
Update: Changed bytes to nybbles - Doh!
Update 2: ++ greenFox for pointing out the why.
In reply to Re: Pack/unpack irregularity
by jsprat
in thread Pack/unpack irregularity
by thor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |