Problem 61065. Convert Hexavigesimal to Decimal
NASA (Ned’s Alien-Spying Agency) have made contact with a 13-fingered race from the planet Genai. Naturally, Ned’s shadowy operatives intend to communicate with the aliens via the universal language of mathematics. However, because of their digitally prodigious physiology, the Genaians use a base-26 number system. This is convenient for humans with an English keyboard, because base-26 can be represented with the letters of the English alphabet: 'a' = 0, 'b' = 1, …, 'z' = 25.
Given an n-element char vector of the characters ‘a’-’z’, return the (decimal) numerical value the vector represents in base 26, treating each character as a digit.
For example, the text ‘aloha’ would correspond to a vector of values [0 11 14 7 0], thus representing the base-26 value 202982 = 11*26^3 + 14*26^2 + 7*26.
Examples
d = char2num26('funfunfun')
d = 1208856210289
d = char2num26('matlab')
d = 142917893
d = char2num26('nasa')
d = 228956
Assumptions
The input will be given as a row vector of characters from 'a' to 'z' (lower case). Concepts like public-key encryption aren't on the agenda yet, so the input vector will be between 1 and 8 elements, meaning the result will be exactly representable in double precision.
Solution Stats
Problem Comments
-
2 Comments
Mohammad Aryayi
22 hours and 34 minutes ago
There's a small issue with the text:
[ ... For example, the text ‘aloha’ would correspond to a vector of values [0 11 14 7 0], thus representing the base-26 value 202982 = 11*263 + 14*262 + 7*26 ...]
It should be:
202982 = 11*26^3 + 14*26^2 + 7*26
Matt Tearle
16 hours and 11 minutes ago
Thanks, Mohammad. I've updated the text.
Solution Comments
Show commentsProblem Recent Solvers45
Suggested Problems
-
Convert Hexavigesimal to Decimal
45 Solvers
More from this Author33
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!