
perlisme
Novice
Feb 1, 2010, 11:51 AM
Post #12 of 14
(1170 views)
|
|
Re: [FishMonger] Writing a binary file
[In reply to]
|
Can't Post
|
|
Lets pretend I just have this hex data in my array and I want to output the hex into a file.
@teb = (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e); foreach my $num ( @teb ) { # printf $FILE "%o", $num; # an unsigned integer, in octal # printf $FILE "%x", $num; # an unsigned integer, in hexadecimal printf $FILE "%b", $num; # an unsigned integer, in binary } close($FILE); Basically I want the perl version of this:
#include <stdio.h> int main() { char teb[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x07, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x07, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x07, 0x2e, 0x30, 0x2e, 0x30, 0x2e }; FILE *fd; fd = fopen("a.teb", "w"); int i; for(i=0; i<sizeof(teb); i++) { fprintf(fd, "%c", teb); } fclose(fd); return 0; } I want to output this hex in @teb into a file. How can I do that?
(This post was edited by perlisme on Feb 1, 2010, 12:00 PM)
|