Tuesday, April 29, 2003
Converting a file to/from hex using Perl
I needed to store binary images in Pick. Pick, of course, doesn't like to store binary (it can't deal with char(255)), so I deceded to convert to hex. I could have uuencoded but hex is fine for my purposes.
So here's how to convert a file.gif to file.gif.hex:
perl -n0777e 'print unpack "H*",$_' < file.gif > file.gif.hex
To convert it back:
perl -n0777e 'print pack "H*",$_' < file.gif.hex > newfile.gif