String to int

Hi, i got stuck parsing a Hex string to an integer. I tried the following:

String keybChars ="FF01";
  for(int i=0; i<4; i++)
    int tmp =  (int)strtol(keybChars[i], NULL, 16);
    Serial.println(tmp, DEC);

put the output is:


Can someone please tell me what im doing wrong? Or tell me a better way to parse a String in HEX format to an integer?

Thank you!

Your problem is that strtol expects a string, but you’re trying to pass it a single character.

The variable type String can cause memory-problems so you should'nt use the variable type String at all

char keybChars[4+1]; // 4 characters plus one byte for terminating zero
keyChars = "FF01";

What is not clear to me what do you want the integer to contain?
is your charsequence meant as 4bit hexadecimals or 8bit hexadecimals or do you want to convert to the ASCII-code?
the further transformation depends on that

best regards Stefan