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.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…