arduino string to hex

Works fine for me:

int x2i(char *s) 
{
  int x = 0;
  for(;;) {
    char c = *s;
    if (c >= '0' && c <= '9') {
      x *= 16;
      x += c - '0'; 
    }
    else if (c >= 'A' && c <= 'F') {
      x *= 16;
      x += (c - 'A') + 10; 
    }
    else break;
    s++;
  }
  return x;
}

void setup ()
  {
  Serial.begin (115200);
  Serial.println (x2i ("42AB"), HEX);
  }  // end of setup

void loop ()
  {
    
  }  // end of loop

Next time please post the whole code, so we can see how you are testing it.

I got:

42AB