Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Aristotle (Chancellor)
on Jul 01, 2003 at 09:58 UTC ( #270430=note: print w/replies, xml ) Need Help??


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

Another take.
use strict; use warnings; use constant OFFS => 1 - ord 'a'; use constant BASE => ord("z") - ord("a") + 1; sub alphabetic_to_base10 { local $_ = shift; my $num = 0; $num = ($num * BASE) + (OFFS + ord $_) for /./g; return $num; } printf "$_: %d\n", alphabetic_to_base10($_) for qw[a z aa az ba zz aaa + zba]; __END__ a: 1 z: 26 aa: 27 az: 52 ba: 53 zz: 702 aaa: 703 zba: 17629

Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://270430]
help
Chatterbox?
[erix]: OT++: /me came across an osprey (=visarend (=Fischadler)) just now
[erix]: (osprey are pretty rare in NL)
[jkva]: erix whereabouts?
[erix]: Hey jkva! I am on Texel at the moment :)
[jkva]: Oh nice :)
[erix]: probably a 'doortrekker' ...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-10-20 10:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (260 votes). Check out past polls.

    Notices?