![]() |
|
|
|||||||
![]() |
VHDL - Hexadecimal to Binary File Conversion Utility |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
This perl script is useful for creating binary files out of text files
containing hexadecimal values. I have found it useful for many a simulation. Vic ------------------------------- cut here #!/usr/bin/perl if ( @ARGV != 2 ) { $0 =~ m%(.*)/(\w+)$%; # Separate script name into path and name die " Usage: $2 <hex_file> <binary_file> Description: Takes a text file with hex bytes (pairs of two hex characters) separated by spaces and converts it into a binary file. Comments can be entered in the text file by preceding them with a pound character. Newlines are ignored except to mark the end of a comment. Example Input File: 12 34 56 78 # These will be the first four bytes of the binary file 9A BC DE F0 # These will be the second four bytes of the binary file 12 34 56 78 # These will be the last four bytes of the binary file Notes: Created by Victor Hannak on 2/20/2004. Feel free to modify and reuse as needed.\n\n\n"; } $HexFile = $ARGV[0]; $BinFile = $ARGV[1]; if ( ! -e $HexFile) { die "\n\nERROR: $ARGV[1] is not a valid filename\n\n\n"; } open(HEXFILE, $HexFile) || die "ERROR: Can't open $HexFile for reading: $!"; open(BINFILE, ">$BinFile") || die "ERROR: Can't open $BinFile for writing: $!"; binmode BINFILE; $BinString = ""; while (<HEXFILE>) { chomp; s/^\s+//; s/\#.*$//; s/\s+$//; s/(\w\w)/hex $1/eg; @array = split; $BinString = $BinString . pack("C*",@array); } print BINFILE $BinString; close HEXFILE; close BINFILE; ------------------------------- cut here Victor Hannak |
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| SONY DVD RW DW-G120A SOMETIMES FAILS...... | atlantic965 | DVD Video | 0 | 06-18-2006 10:36 PM |
| problems backing up dvds | Lawrence Traub | DVD Video | 11 | 09-27-2005 07:34 PM |
| file conversion size/quality issues | RichA | DVD Video | 0 | 03-02-2005 05:24 AM |
| Re: Ripping DVDs. Please answer the attached question. - Question.txt | Stan Brown | DVD Video | 19 | 02-09-2005 11:19 PM |
| Burn process failed - help! Log file posted for help troubleshooting | Michael Mason | DVD Video | 1 | 08-16-2004 09:24 PM |