[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] file hex form converter reference
From: |
Ned Konz |
Subject: |
Re: [avr-gcc-list] file hex form converter reference |
Date: |
Mon, 29 Nov 2004 21:03:03 -0800 |
User-agent: |
KMail/1.7.1 |
On Monday 29 November 2004 3:19 am, Leo Hendrawan wrote:
> i/m looking for a C/C++ reference/source which could convert any file type
> (esp. imag files) to hex form that could be included inside a C source for
> AVR-gcc application.
I don't know how important the choice of language is, but here's a little Perl
program that does just that:
my $bytes = unpack("H*", join("", (<ARGV>)));
$bytes =~ s/(..)/0x$1, /g;
$bytes =~ s/(.{1,72})/ $1\n/g;
print "const uint8_t PROGMEM myArray[] = {\n$bytes};\n";
And here's its output when run on itself:
$ perl hexdump.pl hexdump.pl
const uint8_t PROGMEM myArray[] = {
0x6d, 0x79, 0x20, 0x24, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x3d, 0x20,
0x75, 0x6e, 0x70, 0x61, 0x63, 0x6b, 0x28, 0x22, 0x48, 0x2a, 0x22, 0x2c,
0x20, 0x6a, 0x6f, 0x69, 0x6e, 0x28, 0x22, 0x22, 0x2c, 0x20, 0x28, 0x3c,
0x41, 0x52, 0x47, 0x56, 0x3e, 0x29, 0x29, 0x29, 0x3b, 0x0a, 0x24, 0x62,
0x79, 0x74, 0x65, 0x73, 0x20, 0x3d, 0x7e, 0x20, 0x73, 0x2f, 0x28, 0x2e,
0x2e, 0x29, 0x2f, 0x30, 0x78, 0x24, 0x31, 0x2c, 0x20, 0x2f, 0x67, 0x3b,
0x0a, 0x24, 0x62, 0x79, 0x74, 0x65, 0x73, 0x20, 0x3d, 0x7e, 0x20, 0x73,
0x2f, 0x28, 0x2e, 0x7b, 0x31, 0x2c, 0x37, 0x32, 0x7d, 0x29, 0x2f, 0x20,
0x20, 0x20, 0x20, 0x24, 0x31, 0x5c, 0x6e, 0x2f, 0x67, 0x3b, 0x0a, 0x70,
0x72, 0x69, 0x6e, 0x74, 0x20, 0x22, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20,
0x75, 0x69, 0x6e, 0x74, 0x38, 0x5f, 0x74, 0x20, 0x50, 0x52, 0x4f, 0x47,
0x4d, 0x45, 0x4d, 0x20, 0x6d, 0x79, 0x41, 0x72, 0x72, 0x61, 0x79, 0x5b,
0x5d, 0x20, 0x3d, 0x20, 0x7b, 0x5c, 0x6e, 0x24, 0x62, 0x79, 0x74, 0x65,
0x73, 0x7d, 0x3b, 0x5c, 0x6e, 0x22, 0x3b, 0x0a,
};
--
Ned Konz
http://bike-nomad.com