Hi,
I am currently working on a program to decode data that is collected on a gps receiver and i've ran into a problem. Some of the data is encoded in IEEE 754. I wrote the following functions to decode the the binary:
these return the correct values but I do not have enough processing power available to use the pow function. Any ideas on a way to decrease cycles? Is there a predefined way in C to convert the binary to IEEE 754? Any help would be appreciated I don't work with C too often. Oh almost forgot, I am running this on a linux platform. Thanks
-Matt
I am currently working on a program to decode data that is collected on a gps receiver and i've ran into a problem. Some of the data is encoded in IEEE 754. I wrote the following functions to decode the the binary:
Code:
/**************************************************************************************************
*Converts binary into IEEE 754 single percision
***************************************************************************************************/
float bin2float(unsigned long binary){
float fp;
unsigned int s=0,e=0,f=0;
s=binary>>31;/*sign bit*/
e=(binary>>23&0xff);/*exponent*/
f=binary&0x7fffff;/*fraction*/
fp=(sign_bit(s)<<(e-127))*(1+f*(pow(2,-23)));
return(fp);
}
/**************************************************************************************************
*Converts binary into IEEE 754 double percision
***************************************************************************************************/
double bin2double(int binary1, int binary2){//binary1=bits 0-31 binary2=bits 32-63
double fp;
unsigned int s=0,e=0,f=0;
s=binary2>>31;/*sign bit*/
e=(binary2>>20&0x7ff);/*exponent*/
f=(binary1*pow(2,-51)+((binary2&0x7ffff)*pow(2,-21)));/*fraction*/
fp=(sign_bit(s)*pow(2,(e-1023)))*(1+f);
return(fp);
}
-Matt
Comment