in reply to How to open a file in hexadecimal form?
then one plan would be to group the string of hex digits into pairs then replace the ones that are "A7" with "00" and rebuild the string -- something like this would do it:B58013A7FF
On the other hand, if you want to treat the file as binary data, and any single byte in the file that happens to have the value 0xA7 (i.e. 167. decimal, 10100111 binary) should be replaced by a null byte, then the plan would be read some number of raw bytes into a scalar, replace 0xA7 with 0x00 throughout, and write the result -- something like this (set up as a stdin > stdout filter):while (<DATA>) { chomp; my $out = ''; while ( /([0-9a-f]{2})/gi ) { $out .= ( uc($1) eq 'A7' ) ? "00" : $1; } print "$out\n"; } __DATA__ b58013A7FF
In case you don't know about stdin > stdout filters, it's just a matter of running the script using redirection from some file for input and redirection to some other file for output, like this:binmode STDIN; binmode STDOUT; $/ = \8192; # set "input record separator" to 8KB per read while (<>) { tr/\xa7/\x00/; print; }
script.pl < input.file > output.file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to open a file in hexadecimal form?
by Anonymous Monk on May 12, 2005 at 05:31 UTC | |
by Roy Johnson (Monsignor) on May 12, 2005 at 12:30 UTC | |
by 5mi11er (Deacon) on May 12, 2005 at 14:25 UTC |