Created
May 20, 2014 17:30
-
-
Save RobotGrrl/8583bae096ff95233d44 to your computer and use it in GitHub Desktop.
Numbers in an array to int
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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