title: convert numbers to 26base with only letters
body: <p>I need to <strong>convert</strong> number in "Alphabetic" Counting System, similar to excel spreadsheets:</p>
  
  <blockquote>
    <p>convert(1) == "A";<br>
    convert(2) == "B";<br>
    ...<br>
    convert(26) == "Z";<br>
    convert(27) == "AA";<br>
    ...<br>
    convert(52) == "AZ";<br>
    convert(53) == "BA";<br>
    ...<br>
    convert(702 ) == "ZZ";<br>
    convert(703 ) == "AAA";  </p>
  </blockquote>
  
  <p>this is my code:</p>
  
  <pre><code>function convert($n){
      if ($n&gt; 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;
  }
  </code></pre>
  
  <p>but the output is a bit off:</p>
  
  <blockquote>
    <p>@, 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,<br>
    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,<br>
    B@, BA</p>
  </blockquote>
  
  <p>I tried to tweak the numbers but I can not make it right, any suggestion for a better algorithm ?</p>