This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ascii str (multidigit) or ptr to decimal conversion

Hello!

I'm using following formula to convert string to decimal value:

int ptr2dec(char *ptr, unsigned char size)
{
int val = 0;
unsigned char x;

for (x = 0; x < (size - 1); x++)
{
val += *ptr - 0x30; // get next

// skip last ,multiply step
if (x == size)
return (val);

val *= 10; // shift left
ptr++;
}
}

The idea is to extract digit one by one, and
shift whole value left by multyplying it by 10. Posted code may have errors becos i writing it from my head. My code does not have any error checks (eg: character in string, overflow etc.)

I'm searching for things that can optiomize my code. Can you give me some examples of yours str/dec conversion ? I'm also interested in assembler solution.

sorry for broken English
regards
LB

0