Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 floatToIntBits in the Float Class, however I am not sure how standard that is.

like image 335
gjrwebber Avatar asked Dec 09 '22 19:12

gjrwebber


1 Answers

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!)

like image 104
Dmitry Brant Avatar answered Feb 15 '23 22:02

Dmitry Brant