title: Converting double to hexadecimal - Code review
body: <p>I have the following code that takes a double value and converts it to a hexadecimal representation, and vice versa.  I would like to know whether there are any potential problems with it - whether I have overlooked something.</p>
  
  <pre><code>double hex_to_double2(string &amp;hexString)
  {
      unsigned char byte_string[sizeof(double)];
      int number;
  
      int j = 0;
  
      for(int i = 0; i &lt; hexString.size() ; i += 2)
      {
          sscanf(&amp;hexString[i], "%02x", &amp;number);
          byte_string[j] = (unsigned char)number;
          ++j;
      }
  
      double p = (double&amp;)byte_string;
      return p;
  }
  
  std::string double_to_hex_string(double d)
  {
      unsigned char *buffer = (unsigned char*)&amp;d;
      int bufferSize = sizeof(double);
  
      char converted[bufferSize * 2];
  
      int j = 0;
      for(int i = 0 ; i &lt; bufferSize ; ++i)
      {
          sprintf(&amp;converted[j*2], "%02X", buffer[i]);
          ++j;
      }
      string hex_string(converted);
      return hex_string;
  }
  </code></pre>
  
  <p>It seems to work fine. But I have been told by someone that <code>char converted[bufferSize * 2];</code> should be <code>char converted[bufferSize * 2 + 1];</code></p>
  
  <p>Is this the case?</p>