unsigned int atoin(char s[]) { int i; unsigned int n; n = 0; i=0; while(s[i]!='\0'){ //for (i = 0; s[i]!='\0'; i++){ if ((s[i] >= '0') && (s[i] (minor)= '9')){ n = (16 * n) +(s[i] - '0');} else{ n = (16 * n) +(s[i] - 'A' + 10);} i++; } return n; }mudy
Hi mudy
The code requires HEX ASCII string to be coded with capitals.
There is a simple trick to make it case independent.
When the character is not between '0' and '9' try this:
n = (16 * n) + ((s[i] - ('a' - '9' - 1)) & 0x0f);
Regards
Mark Butcher
www.mjbc.ch / www.uTasker.com