Base36 to base10 convert

Hi Guys,

I'm currently having problem to decode the string from base36 to base10 (Decimal). Is there any open source or library i can use to do the conversion?

Thank you in advance.

Please see if this helps:

https://forum.arduino.cc/index.php?topic=264925.msg1868553#msg1868553

Thanks for replied, yup this i found before. This is from base 10 to base 36. The answer i need is from base 36 to base 10

This should work (using the same example as from the thread)

void setup() {
  Serial.begin(115200);
  char b36[]="NAWELU";
  Serial.println(ToBase10(b36),DEC);
}

void loop() {
}

uint32_t ToBase10 (char base36[]) {
  uint32_t base10=0;
  uint8_t digit=0;
  char c = base36[digit];
  while (c!='\0') {
    base10=base10*36;
    if ((c>='0') && (c<='9')) {
      base10=base10+ ((uint8_t) c -48);
    }
    else if ((c>='A') && (c<='Z')) {
      base10=base10+ ((uint8_t) c -55);
    }
    else return 0;
    digit++;
    c = base36[digit];    
  }
  return base10;
}

there is no overflow checking !

or use strtol (Base36 - Wikipedia)

/*
strtol( const char *s, char **p, int base );

Where:
const char *s
is the string to be converted into a long integer. This string may consist of any number of blanks and/or tabs, possibly followed by a sign, followed by a string of digits.

char **p
points to a pointer that will be set to the character immediately following the long integer in the string "s". 
If no integer can be formed from "s", "strtol" makes "*p" point to the first character of "s". If "p" is the NULL pointer, this sort of action does not take place.

int base
is the base for the number represented in the string. 
8 => octal
10 => decimal
16 => Hexadecimal
(Maximum base value is 36)
If base is zero, the string is assumed to be decimal unless the string to be converted starts with O (for Octal), Ox (for hex) or OX (for hex)
*/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);

  char str[]="0xABC";
  uint16_t num = strtol(str,NULL,16);
  delay(1000);
  Serial.print(num,DEC);

}

void loop() {
  // put your main code here, to run repeatedly:

}
      base10=base10+ ((uint8_t) c -48);
    }
    else if ((c>='A') && (c<='Z')) {
      base10=base10+ ((uint8_t) c -55);

That would be a LOT easier to understand, without needing to refer to a web page, as:

     base10=base10+ ((uint8_t) c - '0');
    }
    else if ((c>='A') && (c<='Z')) {
      base10=base10+ ((uint8_t) c - 'A');

PaulS:
That would be a LOG easier to understand, without needing to refer to a web page

details ! btw shouldn't i be

(uint8_t) ( c - '0');

then ? and isn't this

base10=base10+ ((uint8_t) c - 'A');

just incorrect !

base10=base10+ 10 + (uint8_t) ( c - 'A');

would work OK.

btw shouldn't i be

I don't think you can be that.