Base 26 to Base 10 Java Code - Realbasic Equivalent?
908117Dec 29 2011 — edited Dec 29 2011I was looking at this article on wikipedia that includes two java algorithums for converting a base 26 number (letters) into a base ten number (0-10) and back again. Does anyone know how to translate this into realbasic code?
What I am looking to do is use a updownarrow control to allow the user to increase or decrease the value of a base 26 number in an editfield by clicking on the updownarrowcontrol. What I need to do is convert the base 26 number into a base 10 base, add or subtract 1, and covert it back into a base 26 number for display in the editfield. Thus aa would become ab if increased by 1 or it would become z if decreased by 1. Conversely zz would become aaa (+1) or zy (-1).
http://en.wikipedia.org/wiki/Hexavigesimal
public static String toBase26(int number){
number = Math.abs(number);
String converted = "";
// Repeatedly divide the number by 26 and convert the
// remainder into the appropriate letter.
do
{
int remainder = number % 26;
converted = (char)(remainder + 'A') + converted;
number = (number - remainder) / 26;
} while (number > 0);
return converted;
}
public static int fromBase26(String number) {
int s = 0;
if (number != null && number.length() > 0) {
s = (number.charAt(0) - 'A');
for (int i = 1; i < number.length(); i++) {
s *= 26;
s += (number.charAt(i) - 'A');
}
}
return s;
}