Split RGBW hex String into integers I have a program where the Arduino receives hex Strings that represent a RGBW color (similar to css for example). My goal is to create that color by using pwm, so I need to convert that one hex string into four integer values between 0..255 to use for the pwm.
Whats the best/easiest way to do this?

Example:

void incomingMessage(const MyMessage &amp;message) {

    // h = hex value
    // message = e.g. (h) #112233AB
    redval = ?; // h11 =&gt; 17
    greenval = ?; // h22 =&gt; 34
    blueval = ?; // h33 = 51
    whiteval = ?; //AB = 171

    analogWrite(RED_PIN, redval);     
    analogWrite(GREEN_PIN, greenval);
    analogWrite(BLUE_PIN, blueval);
    analogWrite(WHITE_PIN, whiteval);

}
I don't like using the String class because it can cause memory fragmentation. This would do it by just using C-style strings:

byte fromhex (const char * str)
  {
  char c = str [0] - '0';
  if (c &gt; 9)
    c -= 7;
  int result = c;
  c = str [1] - '0';
  if (c &gt; 9)
    c -= 7;
  return (result &lt;&lt; 4) | c;
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  const char * test = "#112233AB";

  byte redval   = fromhex (&amp; test [1]);
  byte greenval = fromhex (&amp; test [3]);
  byte blueval  = fromhex (&amp; test [5]);
  byte whiteval = fromhex (&amp; test [7]);

  Serial.println ((int) redval);
  Serial.println ((int) greenval);
  Serial.println ((int) blueval);
  Serial.println ((int) whiteval);

  }  // end of setup

void loop ()
  {
  // whatever   
  }  // end of loop


Output:

17
34
51
171


That does not do any validation (that the string is indeed 9 characters long, and contain hex characters) but I'll leave that for you to do. :)