floating point - Converting int16 to float in C -


how convert 16 bit int floating point number?

i have signed 16 bit variable i'm told need display accuracy of 3 decimal places, presume involve conversion float?

i've tried below copy's 16 bits float doesn't seem right.

float myfloat = 0; int16_t myint = 0x3e00; memcpy(&myfloat, &myint, sizeof(int)); 

i've read half-precision floating-point format unsure how handle this... if need to.

i'm using gcc.

update: source of data char array [2] i2c interface. stitch signed int.

can help?

i have signed 16 bit variable i'm told need display accuracy of 3 decimal places

if told integer value can displayed way he/she should start c begginers course.

the possibility integer value has been scaled (multiplied). example value of 12.456 can stored in integer if multiplied 1000. if case:

float flv; int intv = 12456;  flv = (float)intv / 1000.0f; 

you can print scaled integer without convering float

printf("%s%d.%03d\n", intv < 0 ? "-": "", abs(intv / 1000), abs(intv % 1000)); 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -