title: Convert binary bitset to hexadecimal (C++)
body: <p>Is there a simple way to convert a binary bitset to hexadecimal? The function will be used in a CRC class and will only be used for standard output.</p>
  
  <p>I've thought about using to_ulong() to convert the bitset to a integer, then converting the integers 10 - 15 to A - F using a switch case. However, I'm looking for something a little simpler. </p>
  
  <p>I found this code on the internet:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;bitset&gt;
  
  using namespace std;
  int main(){
      string binary_str("11001111");
      bitset&lt;8&gt; set(binary_str);  
      cout &lt;&lt; hex &lt;&lt; set.to_ulong() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>It works great, but I need to store the output in a variable then return it to the function call rather than send it directly to standard out.</p>
  
  <p>I've tried to alter the code but keep running into errors. Is there a way to change the code to store the hex value in a variable? Or, if there's a better way to do this please let me know.</p>
  
  <p>Thank you. </p>