In my C ++ code, I declared a union:
typedef union U_FloatParse {
float float_data;
unsigned char byte_data[4];
} U_FloatConvert;
Then I set the byte_data array with values 0, 0, 192, 127:
U_FloatConvert depth_data;
depth_data.byte_data[0] = 0;
depth_data.byte_data[1] = 0;
depth_data.byte_data[2] = 192;
depth_data.byte_data[3] = 127;
printf("\n\nFloat = %f\n\n", depth_data.float_data);
As a conclusion, I get NaN. Why am I not getting a normal float value? When I pass the values: 56, 137, 33, 63. I get a float value of 0.631000.
Test code: http://codepad.org/Q8ds1V0F
source
share