uint16_t pack_float_12_4 float uint16_t decimal uint16_t uint16_t poin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
uint16_t pack_float_12_4(float f) {
uint16_t decimal = (uint16_t) f;
uint16_t points = (uint16_t) ((f - (float) decimal) * 10);
if (decimal > 0xFFF)
decimal = 0xFFF;
return (decimal << 4) | (points & 0xF);
}
float unpack_float_12_4(uint16_t s) {
return (float) (s >> 4) + (float) (s & 0xF) / 10.0f;
}