Sending 32-bit float variable with 16-bit data format

I needed to send a 32-bit float variable with a 16-bit data format. In this case, we can transmit the data by sacrificing some less significant bits. This is the code for the conversion of 32-bit float into 16-bit unsigned integer, and re-conversion from the 16-bit unsigned integer to 32-bit float. This code would be especially useful when you program some embedded system.

This is the result of execution of this code.

I got some ideas from this thread.
https://stackoverflow.com/questions/21005845/how-to-get-float-bytes

Good luck!

Leave a Reply