c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $count = 17767; my $c16 = pack('S', $count); printf(qq{Count = dec %d, hex 0x%04x, c16 = 0x%04x \n}, $count, $count, $c16); " Argument "gE" isn't numeric in printf at -e line 1. Count = dec 17767, hex 0x4567, c16 = 0x0000 #### c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $count = 17767; printf qq{%d decimal, %x hex \n}, $count, $count; ;; for my $template (qw(S n v N V)) { printf qq{template '$template': }, $template; my $p = pack $template, $count; printf '%02x ', $_ for unpack 'C*', $p; print ''; } " 17767 decimal, 4567 hex template 'S': 67 45 template 'n': 45 67 template 'v': 67 45 template 'N': 00 00 45 67 template 'V': 67 45 00 00