title: Quickly convert raw data to hex string in c++
body: <p>I'm reading data from a file and trying to display the raw data as 2 digit hex strings.</p>
  
  <p>I'm using the Qt framework, specifically the QTextEdit.</p>
  
  <p>I've tried a bunch of different approaches and have almost accomplished what I want it to do, however it has some unexpected errors I don't know anything about.</p>
  
  <p>Currently this is my implementation:</p>
  
  <p>1) Read in the data:</p>
  
  <pre><code>ifstream file (filePath, ios::in|ios::binary|ios::ate);
  if (file.is_open())
  {
      size = file.tellg();
      memblock = new char [size+1];
      file.seekg(0, ios::beg);
      file.read(memblock, size);
      file.close();
  }
  </code></pre>
  
  <p>2) Create a single QString that will be used (because QTextEdit requires a QString):</p>
  
  <pre><code>QString s;
  </code></pre>
  
  <p>3) Loop through the array appending each successive character to the QString s.</p>
  
  <pre><code>int count = 0;
  for(i=0;i&lt;size;i++)
  {
      count++;;
      s.append(QString::number(memblock[i], 16).toUpper());
      s.append("\t");
      if (count == 16)
      {
          s.append("\n");
          count -= 16;
      }
  }
  </code></pre>
  
  <p>Now this works fine, except when it reaches a character <code>FF</code>, it appears as <code>FFFFFFFFFFFFFFFF</code></p>
  
  <p>So my main questions are:</p>
  
  <ol>
  <li><strong>Why do only the 'FF' characters appear as 'FFFFFFFFFFFFFFFF' instead?</strong></li>
  <li><strong>Is there a way to convert the char data to base 16 strings without using QString::number?</strong></li>
  </ol>
  
  <p>I want this implementation to be as fast as possible, so if something like sprintf could work, please let me know, as I would guess that might be faster that QString::number.</p>