Jan 20, 2005 #1 D 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
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
Jan 20, 2005 #2 S stormwolf Advanced Member level 4 Joined Jan 3, 2004 Messages 112 Helped 12 Reputation 24 Reaction score 0 Trophy points 1,296 Activity points 777 You can try the function "pack " in perl.
Jan 20, 2005 #3 N nand_gates Advanced Member level 3 Joined Jul 19, 2004 Messages 899 Helped 175 Reputation 350 Reaction score 53 Trophy points 1,308 Activity points 7,037 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
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