Single precision floating point conversion converter decoder makes it readable

Dependents:   AMIS30543

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SP_FP.cpp Source File

SP_FP.cpp

00001 #include "SP_FP.h"
00002 #include "mbed.h"
00003 
00004 SP_FP::SP_FP() {
00005     result = 0.0f;
00006     value_Temp = 0;
00007 }
00008 
00009 float SP_FP::decoder(uint32_t VALUE) {
00010     (VALUE >> 31) ? result = -1.0f : result = 1.0f;  // Determine sign
00011     value_Temp = VALUE << 1;  // Delete sign bit
00012     value_Temp = value_Temp >> 24;  // Make it alone only exponent
00013     result *= pow(2.0f, ((float) ((int) value_Temp - 127)));  // E (will be pow of 2) = X - 127
00014     value_Temp = VALUE << 9;  // Delete after 23rd bit
00015     value_Temp = value_Temp >> 9;  // Make it alone only mantissa (fraction, significand)
00016     result *= 1.0f + (float) value_Temp / 8388608.0f;  // pow(2.0, 23.0) thanks to http://softelectro.ru
00017     return result;
00018 }