#include <stdio.h>
#include <stdint.h>
float combine_16bit_to_float(uint16_t high, uint16_t low) {
union {
uint32_t u;
float f;
} float_union;
float_union.u = ((uint32_t)high << 16) | (uint32_t)low;
return float_union.f;
}
int main() {
uint16_t high = 0x42F6;
uint16_t low = 0xE666;
uint16_t temp_buf[8] ;
float result;
float result1;
temp_buf[2]= 0x42F6;
temp_buf[3]= 0xE666;
result = combine_16bit_to_float(high, low);
result1 = combine_16bit_to_float(temp_buf[2], temp_buf[3]);
printf("High part: 0x%04X\n", high);
printf("Low part: 0x%04X\n", low);
printf("High part: 0x%04X\n", temp_buf[2]);
printf("Low part: 0x%04X\n", temp_buf[3]);
printf("Resulting float: %f\n", result);
printf("Resulting1 float: %f\n", result1);
return 0;
}