Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Generate hex data in perl?

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
Hello all,

I want to write a perl script to generate the hex data,
the command maybe "perl hex.pl hex_file start_hex end_hex".

E.g. start_hex is 00b5 and end_hex is 00be, the hex_file
will look like:

00b5
00b6
00b7
00b8
00b9
00ba
00bb
00bc
00bd
00be

Is it possible? Thanks!

BTW, if I want to generate a binary list like this hex one,how to?

DAVY
 

You can try the function "pack " in perl.
 

Here is the script hex.pl

Code:
#!/usr/bin/perl -w
$start_hex = $ARGV[1];
$end_hex = $ARGV[2];
open(OUTPUT, ">$ARGV[0]") or die "ERROR : Cannot open $ARGV[0].\n";		# Open output file
for ($i = hex($start_hex); $i <= hex($end_hex); $i++) {
    printf OUTPUT "%.4x\n", "$i"; 
}

Here is the command .....
hex.pl hex_file start_hex end_hex

Hope this helps
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top