Looking for a way to convert a binary (or even a text) file into a Perl, Pascal/Delphi, C/C++, or Java source code array? For example, you may want to do this to include a GIF or other binary file directly inside your Perl CGI script, rather than reading the data from a file to reduce file access. If you're writing Windows programs, you could use the same method to store resource files in your executable files.
perl bin2hex.pl banner.gif 0 >source.txt
Listing #1 : TEXT code. Download demo1.bat (0.17 KB).
# begin binary data:
$bin_data = # 42
"x47x49x46x38x39x61x01".
"x00x01x00x80x00x00x00x00".
"x00xFFxFFxFFx21xF9x04".
"x01x00x00x00x00x2Cx00x00".
"x00x00x01x00x01x00x40".
"x02x01x44x00x3B";
# end binary data. size = 42 bytes
$bin_data = # 42
"x47x49x46x38x39x61x01".
"x00x01x00x80x00x00x00x00".
"x00xFFxFFxFFx21xF9x04".
"x01x00x00x00x00x2Cx00x00".
"x00x00x01x00x01x00x40".
"x02x01x44x00x3B";
# end binary data. size = 42 bytes
Listing #2 : TEXT code. Download result1.txt (0.27 KB).