How do I create a .gif file from the following HEX stream:
0d 0a 0d 0a 47 49 46 38 39 61 01 00 01 00 80 ff 00 ff ff ff 00 00 00 2c 00 00 00 00 01 00 01 00 00 02 02 44 01 00 3b
3b is the GIF file terminator
I’m trying to do it following the guide at http://en.wikipedia.org/wiki/Graphics_Interchange_Format#Example_GIF_file
I’d like to implement this in either Perl or C/C++. Any language will do though.
Many thanks in advance,
Thanks guys for all the replies. I removed the leading ‘0d 0a 0d 0a’…
Here’s what I have sofar:
#!/usr/bin/perl
use strict;
use warnings;
open(IN,"<test.txt");
open(OUT,">test.gif");
my @lines=<IN>;
foreach my $line (@lines){
$line=~s/\n//g;
my @bytes=split(/ /,$line);
foreach my $byte (@bytes){
print OUT $byte;
}
}
close(OUT);
close(IN);
You can do it in the shell, using GNU
echo:You can also use the
xxdcommand which will “make a hexdump or do the reverse”. Annoyingly, however, it seems very picky about the input format. Here’s an example usingxxd:gvimhas an interface toxxd. Use the “Tools → Convert To Hex” menu option (keyboard::%!xxd) and then “Tools → Convert Back” (:%!xxd -r).EMACS also has a built-in hex editor, which is accessed by
M-x hexl-mode(see Editing Binary Files in the manual). It’s also a little bit annoying, because you have to typeC-M-x(i.e. Ctrl-Meta-X) before entering a character by its hex code:Of course, it is very easy to write a simple C program to do the conversion:
usage:
Also: many answers here in this code golf question.