Java: Bytes to floats / ints

前端 未结 5 1261
醉梦人生
醉梦人生 2020-12-30 05:21

I have a byte array sent via UDP from x-plane. The bytes (4) are all floats or integers… I tried to cast them to floats but no luck so far…

Example array: byte d

5条回答
  •  一向
    一向 (楼主)
    2020-12-30 05:39

    Use a DataInputStream as follows:

        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));
        float f = dis.readFloat();
    
        //or if it's an int:        
        int i = dis.readInt();
    

提交回复
热议问题