title: Objective C: converting hex (NSInline) to decimal per byte
body: <p>I'm converting a hex <code>characteristic.value</code> (NSinline) to decimal.</p>
  
  <p>This piece of data is the following: <code>&lt;d1448fe0 a1b1c827 efecdf87 a05b1907 5e4e62ec&gt;</code> which is 20 bytes. I want to then store each byte in an array of size 20. I'm curious if there is a more efficient way to parse this one byte at a time. My current code pasted below is working, but it's slow given my sampling rate is about 250 Hz.               </p>
  
  <p>I put the hex value into a string then into an array of chars then parse loop through the whole thing.</p>
  
  <p>Any ideas? Thanks in advance</p>
  
  <pre><code>            int xval[20];
              NSString *val = @"";
              val = [val stringByAppendingFormat: @"%@",characteristic.value];
  
              const char *c = [val UTF8String];
              int number = [temp intValue];
              int counter_filler = 0;
              NSString *toFill = @"";
              int xval_counter = 0;
              unsigned binar;
  
  
              for (int i = 0; i &lt; strlen(c);i++)
              {
                  if (c[i] != '&lt;' &amp;&amp; c[i] != '&gt;' &amp;&amp; c[i] != ' ')
                  {
                  if (counter_filler == 2)
                  {
                      counter_filler = 0;
                      toFill = @"";     
                  }
                  // make it a string
                  toFill = [toFill stringByAppendingFormat: @"%c",c[i]];
                  if (counter_filler == 1)
                  {
                       NSScanner *scanner = [NSScanner scannerWithString:toFill];
                      [scanner scanHexInt:&amp;binar];
                      xval[xval_counter] = binar;
                      xval_counter++;
                  }
  
                  counter_filler++;
                  }
  
              }
  </code></pre>