Sign in to follow this  

Convert byte array to float

This topic is 4613 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know how to convert a byte array into a float? I know how to convert it into an int, but converting from an int to a float is not working correctly so that approach is out. Any suggestions would be helpful, thanks in advance!

Share this post


Link to post
Share on other sites
Can you post some code as to what exactly you are trying to do. Your description is a little vauge.


Do you have an array like this
unsigned char array[];

And what to put everything in it into a float array ?
float array2[];

Then its easy, just do

for(int i = 0; i < sizeOfArray; i++)
array2[i] = array[i];


That's it.

Share this post


Link to post
Share on other sites
Sorry for the confusion. I am coding in Java and dealing with sending information over the network through TCP/IP protocol.

I have a byte array so its something like byte[] buffer; This byte array holds the bytes of the float (4 bytes long since that is how long a float is). I need to convert this into a float, which is something like float f; Is that clear?

Share this post


Link to post
Share on other sites
Well in C++, it would simply be something like this

unsigned char byteArray[size];
float *floatArray = &byteArray[0];



Or if you have a byte array allocated with the "new" keyword

unsigned char *byteArray = new unsigned char[size];
float *floatArray = (float *)byteArray;

Share this post


Link to post
Share on other sites
Sign in to follow this