Aer Interpreter Source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
577 B

  1. class Program {
  2. private string num2alpha(int $n) {
  3. string $r = '';
  4. for(int $i = 1; $n >= 0 && $i < 10; $i++) {
  5. $r = chr(0x41 + ($n % pow(26, $i) / pow(26, $i - 1))) + $r;
  6. $n -= pow(26, $i);
  7. }
  8. return $r;
  9. }
  10. private int alpha2num(string $a) {
  11. int $r = 0;
  12. int $l = strlen($a);
  13. for(int $i = 0; $i < $l; $i++) {
  14. $r += pow(26, $i) * (ord($a[$l - $i - 1]) - 0x40);
  15. }
  16. return (int) $r - 1;
  17. }
  18. public void main() {
  19. import('math');
  20. var_dump($this->alpha2num("Salut"), $this->num2alpha(1723), $this->num2alpha(9854), $this->alpha2num("Base64"));
  21. }
  22. }