#!/usr/bin/perl -w $source = $ARGV[0]; $dest = $ARGV[1]; unless($source and $dest) { print "Usage: perl bin2hex sourcefile destfile\n"; exit 0; } $/=\1; open SRC, "$source"; open DST, ">$dest"; if (defined(SRC) and defined(DST)) { print DST "unsigned char data[] = {\n "; $n=0; while () { if ($n==8) {$n=0; print DST "\n ";} $toprint = ord $_; if ($toprint < 16) {printf DST "0x0%x, ",$toprint;} else {printf DST "0x%x, ",$toprint;} $n++; } print DST "\n}"; close SRC; close DST; }