title: Reading floats in C++ equivalent in Java
body: <p>I have a binary file which supposed to contain 32-bit floating point numbers.
  This file was written out from Objective-C code.
  My task is to read this file in Java.</p>
  
  <p>I think i managed to do it in C++:</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  int main() {
      float f;
      std::ifstream fin("effect_0.cube", std::ios::binary);
      while (fin.read(reinterpret_cast&lt;char*&gt;(&amp;f), sizeof(float))) {
        std::cout &lt;&lt; f &lt;&lt; "\n";
      }
  
      return 0;
  }
  </code></pre>
  
  <p>This is how i interpret a float in Java</p>
  
  <pre><code>InputStream is = new FileInputStream("effect_0.cube");
  DataInputStream dataInputStream = new DataInputStream(is);
  float f = dataInputStream.readFloat();
  </code></pre>
  
  <p>But this returns totally wrong values.</p>
  
  <p>I am running all this on OSX.</p>
  
  <p>The file is <a href="https://drive.google.com/file/d/1GQwe8WZGZdhEYDLE90e6V6KtlKQi75fC/view?usp=sharing" rel="nofollow noreferrer">here</a>. It is very small. The values from C++ seem right, because they are in the correct range, but i got totally different values in Java. I also provide the <code>hexdump -n 16 -s 256</code>:</p>
  
  <pre><code>0000100 00 00 00 00 91 90 90 3e 00 00 00 00 00 00 80 3f
  0000110
  </code></pre>