c语言中Java字节数组到浮点的转换#

c语言中Java字节数组到浮点的转换#,java,c#,udp,byte,Java,C#,Udp,Byte,我正在通过网络将UDP数据包从java发送到C。 数据包成功接收。我正在发送字节数组中的一些值。字节数组是Little Endian格式。因此C#可以直接读取,而无需转换为大端。前2个字节是一个短值,我用C#with成功读取了它 然后有七个浮点值要读取 我试着用英语读它们 public float floatConversion(byte[] bytes,int index) { float myFloat = BitConverter.ToSingle(bytes,index);

我正在通过网络将UDP数据包从java发送到C。 数据包成功接收。我正在发送字节数组中的一些值。字节数组是Little Endian格式。因此C#可以直接读取,而无需转换为大端。前2个字节是一个短值,我用C#with成功读取了它

然后有七个浮点值要读取

我试着用英语读它们

public float floatConversion(byte[] bytes,int index)
{
    float myFloat = BitConverter.ToSingle(bytes,index);
    return myFloat;
}
但它给出了错误的值。 这里是c语言的主要部分#

下面是我从中发送数据包的java代码

 DatagramSocket socket = new DatagramSocket();
    short cc = 9999;
    float   x=66.2342f,
            y=44.6133f,
            z=99.4424f,
            rX=22.7789f,
            rY=11.9911f,
            rZ=99.1254f;
    float anim=96.1133f;
    ByteBuffer buffer =ByteBuffer.allocate(30);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.putShort(cc);
    buffer.putFloat(x);
    buffer.putFloat(y);
    buffer.putFloat(z);
    buffer.putFloat(rX);
    buffer.putFloat(rY);
    buffer.putFloat(rZ);
    buffer.putFloat(anim);
    System.out.println(buffer.array().length);
    DatagramPacket packet = new DatagramPacket(buffer.array(),buffer.array().length,InetAddress.getByName("192.168.1.2"),8888);
    socket.send(packet);

这有什么问题,我该如何解决?谢谢。

调用c#方法时更新索引的代码在哪里?对不起,补充说:我想我发现了问题,主要是我弄错了索引
        UdpClient client = null;
        try
        {
            client = new UdpClient(8888);
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }

        IPEndPoint server = new IPEndPoint(IPAddress.Broadcast,8888);
        byte[] packet = client.Receive(ref server);
        Console.WriteLine(packet.Length);
        Console.WriteLine(getShort(packet,0));
        Console.WriteLine(getFloat(packet, 3));
        Console.Read();
 DatagramSocket socket = new DatagramSocket();
    short cc = 9999;
    float   x=66.2342f,
            y=44.6133f,
            z=99.4424f,
            rX=22.7789f,
            rY=11.9911f,
            rZ=99.1254f;
    float anim=96.1133f;
    ByteBuffer buffer =ByteBuffer.allocate(30);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.putShort(cc);
    buffer.putFloat(x);
    buffer.putFloat(y);
    buffer.putFloat(z);
    buffer.putFloat(rX);
    buffer.putFloat(rY);
    buffer.putFloat(rZ);
    buffer.putFloat(anim);
    System.out.println(buffer.array().length);
    DatagramPacket packet = new DatagramPacket(buffer.array(),buffer.array().length,InetAddress.getByName("192.168.1.2"),8888);
    socket.send(packet);