• 10-01-2008
rainman39393
I am writing a program that converts arabic numbers to mayan numbers and vice versa. I got the converting arabic numbers to mayan down perfect but I am really struggling to write a function converting mayan numbers to arabic. incase you don't know arabic numbers are regular 1 2 3 numbers and mayan numbers are represented by 0 . and -
the conversion table looks like this

0 0 | 5 - | 10 -- | 15 ---
1 . | 6 .- | 11 .-- | 16 .---
2 .. | 7 ..- | 12 ..-- | 17 ..---
3 … | 8 …- | 13 …-- | 18 …---
4 …. | 9 ….- | 14 ….-- | 19 ….---

mayan numbers are base 20 and written backward so to Covert Mayan to Arabic you go like this:
Mayan = ..-- .. ….--- 0 (12 2 19 0)
Arabic = 0 * 20^0 + 19 * 20^1 + 2 * 20^2 + 12* 20^3 = 97180

I read in the Mayan number as a char array and now have to create a function that converts the mayan number and returns an arabic number. This is what I have written so far but I am afraid I went in the completely wrong direction and there is a much easier way to solve this than I am attempting to. Any help would be great, Thanks!
Code:

```        int counter=0;         int final=0;         int temp[20];         int temp2[50];         for(int q=0; q < 50; q++)                 temp2[q] = 0;         for(int j=0; j < 20; j++)                 temp[j] = 0;         for(int t=0; t < 25; t++)         {                 for(int p=0; p < 25; p++)                 {                 if(MayanNumber[t] != '#') //MayanNumber array is declared as all #'s after the number                 {                         if(MayanNumber[t] != ' ')                         {                         switch(MayanNumber[t])                         {                                 case '0':                                         temp[counter] = 0;                                         counter++;                                         break;                                 case '.':                                         temp[counter] = 1;                                         counter++;                                         break;                                 case '-':                                         temp[counter] = 5;                                         counter++;                                         break;                         }                         }                         else                         {                                 for(int k=0; k < counter; k++)                                         temp2[p] = temp2[p] + temp[k];                         }                 }                 }         }         //I havent written the part that tallys up every number yet but it will be assigned to 'final'         return final;```
• 10-01-2008
master5001
>>mayan numbers are base 20 and written backward so to Covert Mayan to Arabic you go like this:

Sounds like a job for strrev() and strtol(). Just put 20 for the third argument of strtol for a base 20 conversion.
• 10-01-2008
tabstop
Quote:

Originally Posted by rainman39393
mayan numbers are base 20 and written backward so to Covert Mayan to Arabic you go like this:
Mayan = ..-- .. ….--- 0 (12 2 19 0)
Arabic = 0 * 20^0 + 19 * 20^1 + 2 * 20^2 + 12* 20^3 = 97180

How is this written backwards? That's how we would normally write in a positional base system. (Largest exponent on the left, just like in base ten).
• 10-02-2008
master5001
Either way, strtol() handles arbitrary bases (within limitation). So you should be fine just converting strings strtol() can digest to mayan format and back. I had to do that for a barcoding system that I wrote a while back. I used a base 25 system that converted to and fro.