user7852: I have a string which I send to the arduino using serial monitor. Something like that:
my specific string 0x0F 0x2C 0x98 0xBC

How can I parse this string in the arduino to get an array of hex values:
0x0F 0x2C 0x98 0xBD

? There are two prerequisites:

All hexadecimal starts with #
The size of hexadecimal is 2. No 0x111 or '0xbbb'


user13432: 
How can I parse this string in the arduino to get an array of hex values:

There are a few standard library (stdlib) functions that can help you with that. Below is a snippet:
char buf[] = "0x0F 0x2C 0x98 0xBD";
uint8_t val[4];

void setup()
{
  Serial.begin(9600);

  char* bp = buf;
  int i = 0;
  do {
    char* ep;
    val[i] = strtol(bp, &ep, 16);
    Serial.println(val[i], HEX);
    bp = ep;
    i += 1;
  } while (*bp != 0);
}

void loop()
{
}

Cheers!

7852: <p>I have a string which I send to the arduino using serial monitor. Something like that:</p>

<pre><code>my specific string 0x0F 0x2C 0x98 0xBC
</code></pre>

<p>How can I parse this string in the arduino to get an array of hex values:</p>

<pre><code>0x0F 0x2C 0x98 0xBD
</code></pre>

<p>? There are two prerequisites:</p>

<ol>
<li>All hexadecimal starts with <code>#</code></li>
<li>The size of hexadecimal is 2. No <code>0x111</code> or '0xbbb'</li>
</ol>
 13432: <blockquote>
  <p>How can I parse this string in the arduino to get an array of hex values:</p>
</blockquote>

<p>There are a few standard library (<a href="http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#gaf8ce3b8dae3d45c34c3b172de503f7b3" rel="nofollow">stdlib</a>) functions that can help you with that. Below is a snippet:</p>

<pre><code>char buf[] = "0x0F 0x2C 0x98 0xBD";
uint8_t val[4];

void setup()
{
  Serial.begin(9600);

  char* bp = buf;
  int i = 0;
  do {
    char* ep;
    val[i] = strtol(bp, &amp;ep, 16);
    Serial.println(val[i], HEX);
    bp = ep;
    i += 1;
  } while (*bp != 0);
}

void loop()
{
}
</code></pre>

<p>Cheers!</p>
