Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Hex to Decimal 2

Status
Not open for further replies.

patraf

Programmer
Sep 28, 2001
5
IE
Hi Folks,
I'm writing a script at the moment where I am searching through several files taking certain data from each one and displaying it in another file. This data is in Hex put I want it in decimal so that I am able to compare it with other results. Has anyone any ideas, all help would be grately appreciated!
Thanks Patrick.
 
Use the printf function as you would in C.

for (@hexvalues) {

printf OUTFILE("%d", $_);

}
 
Here's a script I call perl_hex_to_dec.pl:

#!/usr/bin/perl -w
use strict;

my $a = "0x3f";

my $num = hex($a);

printf "hex=%x, dec=%d\n", $num, $num;

---------------------------------------------

Also, the perl "pack" and "unpack" functions can do things
with hex <-> decimal conversions.

HTH. Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top