convert 16 bit “half float” to 32 bit float

See also:
IEEE 754 single-precision binary floating-point format: binary32

16-bit Floating-Point Rules

float convert16to32float(unsigned int Xi_Value)
{ 
 //TODO:test, imporve, optimize..
  int exp = (Xi_Value>>10) & 0x01f;
  float g=0;
  unsigned int *i=(unsigned int *) & g;
  Xi_Value &= 0xffff;
  *i=0;
  *i |= Xi_Value << 16 & 0x80000000; //sign
  *i |= (exp-15+127) << 23; //exponent 
  *i |= (Xi_Value & 0x3FF) << 13; //value
  return g;
}
Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: