title: String to Hex value conversion in C++
body: <p>Is there a way where a couple of integers put into a string(by concatenation) and when that string is read character by character and printed as hex, the hex values of those numbers are equivalent to numbers themselves.</p>
  
  <p>Example:</p>
  
  <ul>
  <li><p>Lets say i have two numbers, 6 and 8 and a string "yahoo".</p></li>
  <li><p>In the first step, i concatenate them and get a single string 
  "6yahoo8" using <code>snprintf()</code>.</p></li>
  <li><p>In the next step, i read that string character by character and print
  out their hex values,</p></li>
  <li><p>i want to obtain final output as: </p>
  
  <p>{0x06, 0x79, 0x61, 0x68, 0x6F,
         0x6F, 0x08}.</p></li>
  <li><p>But my program is printing the result:</p>
  
  <p>{0x36, 0x79, 0x61, 0x68, 0x6F,
  0x6F, 0x38}.</p>
  
  <p>This result is correct except first and last byte.
  Any ideas how to accomplish the task like i wanted to?
  Advice is very much appreciated.</p>
  
  <p>The program i am using to form the string:</p>
  
  <pre><code>string encode_url() {
      StringAccum sa;
      string url;
      const char *str = "yahoo";
      int p = 6;
      int q = 8;
      sa.snprintf(1,"%x", p);   // snprintf(len, format, value);
      sa &lt;&lt; str.c_str();
      sa.snprintf(1, "%x", q);
      url = string(sa.take_string().c_str());
      return url;
  }
  </code></pre>
  
  <p>There are some customary functions that we use like StringAccum, which is basically String Accumulator in C++.</p></li>
  </ul>