in reply to Reverse Hexadecimal Translation
I wouldn't do it that way very often, though. The internal conversion routine is much faster.my %table = ( 'a' => '10', 'b' => '11', 'c' => '12', 'd' => '13', 'e' => '14', 'f' => '15', ); my @numbers = ('a0', '11', 'ff', '9084fe', '10'); foreach my $trial (@numbers) { my @digits = split //, $trial; my $result = 0; foreach my $digit (@digits) { $result *= 16; $result += $digit =~ /\d/ ? $digit : $table{lc($digit)}; } print "$trial is actually $result\n"; }
modified on 9 April 'cuz btrott is right in his comment, that sneaky japh.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Reverse Hexadecimal Translation
by btrott (Parson) on Apr 10, 2000 at 05:32 UTC |