I need to **convert** number in "Alphabetic" Counting System, similar to excel spreadsheets:

> 
> convert(1) == "A";  
> 
>  convert(2) == "B";  
> 
>  ...  
> 
>  convert(26) == "Z";  
> 
>  convert(27) == "AA";  
> 
>  ...  
> 
>  convert(52) == "AZ";  
> 
>  convert(53) == "BA";  
> 
>  ...  
> 
>  convert(702 ) == "ZZ";  
> 
>  convert(703 ) == "AAA"; 
> 
> 
> 

this is my code:

```
function convert($n){
    if ($n> 26) {
        $tmp = floor($n / 26);
        $n= $n % 26;
        $result = chr(($tmp - 1) + 65) . chr(($n - 1) + 65);
    } else {
        $result = chr(($n- 1) + 65);
    }
    return $result;
}

```

but the output is a bit off:

> 
> @, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,  
> 
>  AA, AB, AC, AD, AE, AF, AG, AH, AI, AJ, AK, AL, AM, AN, AO, AP, AQ, AR, AS, AT, AU, AV, AW, AX, AY,  
> 
>  B@, BA
> 
> 
> 

I tried to tweak the numbers but I can not make it right, any suggestion for a better algorithm ?