title: What is the correct way to output hex data to a file?
body: <p>I've read about <code>[ostream] &lt;&lt; hex &lt;&lt; 0x[hex value]</code>, but I have some questions about it</p>
  
  <p>(1) I defined my file stream, <code>output</code>, to be a hex output file stream, using <code>output.open("BWhite.bmp",ios::binary);</code>, since I did that, does that make the <code>hex</code> parameter in the <code>output&lt;&lt;</code> operation redundant?</p>
  
  <p>(2)
  If I have an integer value I wanted to store in the file, and I used this:</p>
  
  <pre><code>int i = 0;
  output &lt;&lt; i;
  </code></pre>
  
  <p>would i be stored in little endian or big endian? Will the endi-ness change based on which computer the program is executed or compiled on?</p>
  
  <p>Does the size of this value depend on the computer it's run on? Would I need to use the hex parameter?</p>
  
  <p>(3) Is there a way to output raw hex digits to a file? If I want the file to have the hex digit 43, what should I use? </p>
  
  <p><code>output &lt;&lt; 0x43</code> and <code>output &lt;&lt; hex &lt;&lt; 0x43</code> both output ASCII 4, then ASCII 3.</p>
  
  <p>The purpose of outputting these hex digits is to make the header for a .bmp file. </p>