Best way to serialize a Float in java to be read by C++ app?

后端 未结 3 2023
[愿得一人]
[愿得一人] 2021-01-06 05:16

I need to serialize a java Float to be read by an application written in C++ over Socket comms. Is there a standard for this? It would be easiest to use the method floatToIn

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 05:52

    That is, in fact, pretty standard. The floatToIntBits function gives you the actual bytes of the IEEE encoding of the float. The only problem is that the bytes will be big-endian, so you'll have to reverse the byte order when reading into your C++ application. (unless your C++ platform is also big-endian!)

提交回复
热议问题