Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Hexadecimal to Binary File Conversion Utility

 
Thread Tools Search this Thread
Old 02-20-2004, 08:54 PM   #1
Default Hexadecimal to Binary File Conversion Utility


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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46