Hello,
I have a question. I want to convert an 10 character long hexadecimal string into an decimal string. I've searched the intire internet and nothing to be found. It either works with only 4 character long hex strings or uses strol, which I can't seem to get working.
My code for 4 digit hex part:
// start of hex to dec decoding
unsigned int hexToDec(String countrycode);
unsigned int countrydecValue = 0;
int nextInt;
for (int i = 0; i < countrycode.length(); i++) {
nextInt = int(countrycode.charAt(i));
if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
nextInt = constrain(nextInt, 0, 15);
countrydecValue = (countrydecValue * 16) + nextInt;
}
// end of hex to dec decoding
Now I have a 10 digit/charachter long one:
which it will do for 8/10 of the way with replacing the int to long:
long hexToDec1(String animalnumberfinal);
long animaldecValue = 0;
int nextInt3;
for (int i = 0; i < animalnumberfinal.length(); i++) {
nextInt3 = int(animalnumberfinal.charAt(i));
if (nextInt3 >= 48 && nextInt3 <= 57) nextInt3 = map(nextInt3, 48, 57, 0, 9);
if (nextInt3 >= 65 && nextInt3 <= 70) nextInt3 = map(nextInt3, 65, 70, 10, 15);
if (nextInt3 >= 97 && nextInt3 <= 102) nextInt3 = map(nextInt3, 97, 102, 10, 15);
nextInt3 = constrain(nextInt3, 0, 15);
animaldecValue = (animaldecValue * 16) + nextInt3;
}
Yet it can't convert the whole string which is a must because I can't use it in piece's!
Sincerely,
Johannes
