visual studio - How to store 10 bit float value in C -


i have radar device. various data coming out device detected object speed, acceleration distance etc. data in 10 bit , 13 bit float values. how print 10 bit , 13 bit float value , how store values ? floats having 32 bit value. tried store in float variable directly gives wrong values.

for 10-bit case, input consists of: bit 15: sign bits 10-14: exponent (exponent = (bits 10-14) + 15) bits 0-9: signficant (1.(bits 0-9))

something should work, although note haven't tested it:

int halffloattoint16(unsigned int input, int shift) {      int exp, output;      // load precision: (1.(precision bits 0-9))     output  = (int)(0x03ff & input);     output += 0x0400;      // apply sign (bit 15)     output  = (0x8000 & input)?(-output):output;      // calculate exponent (bits 10 - 14)     // adjustment -25 = -15 exponent , -10 significand     exp  = (int)((0x001f) & (input >> 10));     exp -= 25;      // apply shift acheive desired fixed point precision     exp += shift;      // shift output     if(exp > 0)     {         return(output << exp);     }     else     {         return(output >> exp);     } } 

here input 16-bit floating point value, specified above, casted unsigned int. shift identifies shift that's been applied output. output of function value times 2 power specified shift. example if expected maximum output value 1 use shift of 14. 16384 represents one. if maximum expected value of output 20000, make shift zero. optimize overall precision of output.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -