Loading...
Logo
Processing Forum
Apparently Processing doesn't support doubles. Is there any other way to work with base64 encoded 64bit floats?

Replies(2)

This should work in JAVA mode but since it uses native libraries it probaly won't work in JAVASCRIPT or ANDROID modes.

Assuming you have a byte array called b[] then to read this as a series of doubles

Copy code
  1. import java.nio.*;

  2. ByteBuffer buf = ByteBuffer.wrap(b);

  3. // The default ByteOrder is BIG_ENDIAN but depending on the source of
  4. // the byte array you may have to change it to LITTLE_ENDIAN
  5. // Only add the next line if it proves neccessary
  6. buf.order(ByteOrder.LITTLE_ENDIAN);

  7. // Each double requires 8 bytes make a double array big enough
  8. double[] darray = new double(b.length / 8);

  9. for(int i = 0; i < darray.length; i++){
  10.       darray[i] = buf.readDouble();
  11. }

Thanks Quarks, that's awesome. I had to change buf.readDouble(); to buf.getDouble(); but it works a treat.