Convert byte array to float
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!
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 = array;
That's it.
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 = array;
That's it.
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?
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?
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;
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;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement