Skip to content

Instantly share code, notes, and snippets.

@RobotGrrl
Created May 20, 2014 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobotGrrl/8583bae096ff95233d44 to your computer and use it in GitHub Desktop.
Save RobotGrrl/8583bae096ff95233d44 to your computer and use it in GitHub Desktop.
Numbers in an array to int
for(int i=0; i<valLen; i++) {
valResult += (val[(valLen-1)-i] - '0')*pow(10, i);
if(DEBUG) Serial << i << ": " << val[(valLen-1)-i] << " " << (val[(valLen-1)-i] - '0') << " " << pow(10, i) << "=" << (val[(valLen-1)-i] - '0')*pow(10, i) << endl;
}
/*
if(valLen > 3) {
valResult += (val[0] - '0')*1000;
valResult += (val[1] - '0')*100;
valResult += (val[2] - '0')*10;
valResult += (val[3] - '0')*1;
} else if(valLen > 2) {
valResult += (val[0] - '0')*100;
valResult += (val[1] - '0')*10;
valResult += (val[2] - '0')*1;
} else if(valLen > 1) {
valResult += (val[0] - '0')*10;
valResult += (val[1] - '0')*1;
} else {
valResult += (val[0] - '0')*1;
}
*/
if(DEBUG) Serial << "Result: " << (int)valResult << endl;
// do something with result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment