Hello Everyone!
I'm really new to everything around Arduino, and this is my first post.
Anyone can tell me how to convert a byte array to a float array? (I googled, failed)
I don't have much experience with C++.
The plan is to send packets via UDP from a pc, and recieve it with Arduino.
Each packet consists of two float values.
The way I converted them in Java:
private static byte[] float2byteArray(float... args) {
ByteBuffer buffer = ByteBuffer.allocate(4 * args.length);
for (float f : args) {
buffer.putFloat(f);
}
return buffer.array();
}
OR (both same effect)
public static byte[] floatToByteArray(float value) {
int intBits = Float.floatToIntBits(value);
return new byte[] {(byte) (intBits >> 24), (byte) (intBits >> 16), (byte) (intBits >> 8), (byte) (intBits)};
}