title: How to write binary (and not hex) in .bin with qt and c++?
body: <p>I am trying to write a binary document. So far, I succeeded in writing a .bin where the content has an hexadecimal format. I would like to have the content in a binary format (0 and 1 only).</p>
  
  <p>Is it possible ?
  How to do it ?
  Am I wrong in my idea and having it in hexadecimal or binary is the same thing ?</p>
  
  <p>Here is my code so far :)</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QDataStream&gt;
  #include &lt;QString&gt;
  #include &lt;QFile&gt;
  #include &lt;iostream&gt;
  #include &lt;QDebug&gt;
  #include &lt;QTextStream&gt;
  void createBinaryFile()
  {
      int a = 22;
  
      QFile file("/home/.../facts.bin");
      if (!file.open(QIODevice::WriteOnly)) {
          std::cerr &lt;&lt; "Cannot open file for writing: "
                &lt;&lt; qPrintable(file.errorString()) &lt;&lt; std::endl;
      return;
      }
      QDataStream out(&amp;file);
      out.setVersion(QDataStream::Qt_4_3);
      out &lt;&lt; quint32(0x12345678) &lt;&lt; a;
      QTextStream writeInConsole(stdout);
      writeInConsole &lt;&lt; a;
  
      file.flush();
      file.close();
  
  }
  void readBinaryFile()
  {
      quint32 n;
      int a;
      QFile file("/home/.../facts.bin");
      if (!file.open(QIODevice::ReadOnly)) {
          std::cerr &lt;&lt; "Cannot open file for reading: "
                &lt;&lt; qPrintable(file.errorString()) &lt;&lt; std::endl;
      return;
  }
  
  QDataStream in(&amp;file);
  in.setVersion(QDataStream::Qt_4_3);
  
  in &gt;&gt; n &gt;&gt; a;
  QTextStream okk(stdout);
  okk &lt;&lt; a;
  }
  
  int main(int argc, char *argv[])
  {
  QApplication app(argc, argv);
  createBinaryFile();
  //readBinaryFile();
  
  return app.exec();
  }
  </code></pre>
  
  <p>And this is the content of facts.bin :
  1234 5678 0000 0016 </p>
  
  <p>Thank you very much for your help ! :)</p>