Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Alpha base-26 to base-10...

by Limbic~Region (Chancellor)
on Jun 30, 2003 at 23:15 UTC ( #270359=note: print w/ replies, xml ) Need Help??


in reply to Alpha base-26 to base-10...

eduardo,
The concise, but less readable form:

#!/usr/bin/perl -w use strict; print base10_it('ba'), "\n"; sub base10_it { my $base_10; my @values = reverse split '' , $_[0]; $base_10 += ((ord($values[$_]) - 96) * 26 ** $_) for (0 .. $#value +s); $base_10; }
The more readable and verbose form:
#!/usr/bin/perl -w use strict; print base10_it('ba'), "\n"; sub base10_it { my $base_10; my $power = 0; my @values = split '' , $_[0]; while (my $val = pop @values) { $base_10 += (ord($val) - 96) * 26 ** $power; $power++; } $base_10; }
Cheers - Limbic~Region


Comment on Re: Alpha base-26 to base-10...
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://270359]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-08-31 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls