Converting int16_t to float teensy 3.2

Status
Not open for further replies.

m_benji

Member
Hi all,

I need to cast a in16_t to float as a library only supports the math calculations in float. Does the compiler have any effect of this.

Sample code:
{

int16_t a = 10; // recorded data point
float b = 0;
memcpy(&b, &a sizeof(a));

examplefunction(b);

}

Why won't this work?
Cheers,
Matt
 
Last edited:
An int16_t is 2 bytes. A float is 4 bytes. All you're doing is copying 2 bytes from a into b. That is not a cast - which isn't what you need anyway. Just assign a to b:
Code:
float b = a;

Pete
 
Status
Not open for further replies.
Back
Top