title: How to convert a char array of hex values to a single integer value in c++?
body: <p>I have a char array of hex values and would like to convert them into a single integer value. I have two issues with the code I am currently using:</p>
  
  <p><strong>Problem 1:</strong> the value stored in strHex after running this is - "0927ffffffc0" when I want it to be "000927C0" - what is the reason for the extra "ffffff" being added?</p>
  
  <p><strong>Problem 2:</strong> I would like a solution to convert a char array of hex values to an integer without using stringstream if possible.</p>
  
  <pre><code>char cArray[4] = { 0x00, 0x09, 0x27, 0xC0 }; // (600000 in decimal)
  
  std::stringstream ss;
  for (int i = 0; i &lt; 4; ++i)
  {
      ss &lt;&lt; std::hex &lt;&lt; (int)cArray[i];
  }
  std::string strHex = ss.str();
  
  int nHexNumber;
  sscanf(strHex.c_str(), "%x", &amp;nHexNumber);
  </code></pre>
  
  <p>nHexNumber should be 600000 when converted and its giving me -64. </p>