String input = "0x12";
int output = 0;
void setup() {
Serial.begin(9600);
output = hexStringToDecimal(input);
Serial.println(output);
}
void loop() {
// put your main code here, to run repeatedly:
}
long hexStringToDecimal(String hexString) {
long decimalValue = 0;
int hexLength = hexString.length();
for (int i = 0; i < hexLength; i++) {
char c = hexString.charAt(i);
int digitValue;
if (c >= '0' && c <= '9') {
digitValue = c - '0';
} else if (c >= 'A' && c <= 'F') {
digitValue = 10 + (c - 'A');
} else if (c >= 'a' && c <= 'f') {
digitValue = 10 + (c - 'a');
} else {
// Handle invalid characters if necessary
continue;
}
decimalValue = (decimalValue * 16) + digitValue;
}
return decimalValue;
}