Arduino 1.6.5 - MEGA2560
I have a simple routine to convert a Hexadecimal string to a uint32_t value, but it is not generating the expected value. Here is the code, and a debug Serial stream.
uint32_t htoli(const char inbuf[]){
uint32_t b=0;
uint16_t a;
uint8_t c;
Serial.print("htoli(\"");
Serial.print(inbuf);
Serial.print("\")=\n");
bool err=false;
while((c=inbuf[a++])&&!err){
c = toupper(c);
Serial.print(" c(chr)=");
Serial.print((char)c);
if(((c>='0')&&(c<='9'))||((c>='A')&&(c<='F'))){
Serial.print(" b=");
Serial.print(b,DEC);
Serial.print(" ");
b=b*16;
Serial.print(" after mul b=");
Serial.print(b,DEC);
Serial.print(" c(dec)=");
c= c-48;
if(c>9)c=c-7;
b = b + c;
Serial.print(c,DEC);
Serial.print(", after add (b=b+c) b=");
Serial.print(b,DEC);
Serial.print("\n");
}
else {
Serial.print("error? ");
err=true;
}
}
//if(err) b=0;
Serial.print("result =");
Serial.println(b,DEC);
return b;
}
Here is the Debug out:
htoli("800")=
c(chr)=8 b=0 after mul b=0 c(dec)=8, after add (b=b+c) b=8
c(chr)=0 b=0 after mul b=0 c(dec)=0, after add (b=b+c) b=0
c(chr)=0 b=0 after mul b=0 c(dec)=0, after add (b=b+c) b=0
result =0
Can anyone tell me why I can't find the problem?
Somewhere between the first and second iteration of the while(), the value of b is reset to Zero?
Chuck.