Byte size shortened

// https://Discourse.Processing.org/t/byte-size-shortened/13765/2
// GoToLoop (2019/Sep/02)

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

static final int BYTES = Float.BYTES;

final byte[] bytes = new byte[BYTES];
final FloatBuffer buf = ByteBuffer.wrap(bytes).asFloatBuffer();

float f;

void setup() {
  println(buf.order(), java.nio.ByteOrder.nativeOrder(), ENTER);

  bytes[0] = (byte) 0xf0;
  bytes[1] = (byte) 0xaa;
  bytes[2] = (byte) 0xf8;
  bytes[3] = (byte) 0x30;

  println(bytes);
  println();

  f = bytes[0] << 030 | bytes[1] << 020 | bytes[2] << 010 | bytes[3];
  println(f); // -2000.0

  f = buf.get(0);
  println(f); // -4.2329994E29

  exit();
}
4 Likes