@albert, You need to becareful when doing the divide, because there is no
ZERO. (Z -> AA not Z->A0).
here is the code:
public static String ExcelMapIntToStr(int n)
{
StringBuilder sb = new StringBuilder();
while(n>0)
{
sb.append((char)(('A' - 1) + (n-1)%26 + 1));
n = (n-1)/26;
}
return sb.reverse().toString();
}
public static int ExcelMapStrToInt(String str)
{
int val = 0;
int base = 1;
for(int i = str.length() - 1; i>=0; i--)
{
val += (str.charAt(i) - ('A' - 1))*base;
base *= 26;
}
return val;
}
On Tue, Feb 1, 2011 at 10:39 AM, albert theboss <[email protected]>wrote:
> Simply L division by 26 gives the answer ...
> like decimal to binary conversion thats it
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.