Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 examining the Monastery: (8)
As of 2014-12-20 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls