title: How to convert a float into a byte array and vice versa?
body: <p>I am trying to convert a <code>float</code> into a primitive <code>byte[]</code> and vice versa:</p>
  
  <pre><code>public byte[] floatToByteArray(final float value)
  {
      return new byte[]
      {
          (byte) (value &gt;&gt; 56),
          (byte) (value &gt;&gt; 48),
          (byte) (value &gt;&gt; 40),
          (byte) (value &gt;&gt; 32),
          (byte) (value &gt;&gt; 24),
          (byte) (value &gt;&gt; 16),
          (byte) (value &gt;&gt; 8),
          (byte) (value)
      };
  }
  </code></pre>
  
  <p>Oddly enough, when I try to shift the newly allocated <code>byte[]</code> back into a <code>float</code>, the result is nothing but rubbish.</p>
  
  <p>However, it would appear as if the same algorithm works just fine when I use the primitive <code>long</code> data type as argument instead.</p>
  
  <pre><code>public byte[] longToByteArray(final long value)
  {
      return new byte[]
      {
          (byte) (value &gt;&gt; 56),
          (byte) (value &gt;&gt; 48),
          (byte) (value &gt;&gt; 40),
          (byte) (value &gt;&gt; 32),
          (byte) (value &gt;&gt; 24),
          (byte) (value &gt;&gt; 16),
          (byte) (value &gt;&gt; 8),
          (byte) (value)
      };
  }
  </code></pre>