Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 rifling through the Monastery: (5)
As of 2015-07-03 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls