编辑代码

#include <stdio.h>
int main () {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
    char data[4]={0x06,0x47,0xff,0x99};
    unsigned char negMantissa;
    unsigned long mantissa,value,exponent;
    float ret;

    mantissa = (((unsigned long)data[1] & 0x7f) << 16) |(((unsigned long)data[2] & 0xff) << 8) |((unsigned long)data[3] & 0xff);
    printf("mantissa = %d\n",value);
    if ((data[1] & 0x80) != 0) // Sign in msb of 2nd byte
    {
        negMantissa = 1;
    }
    else
    {
        negMantissa = 0;
    }
    exponent = (unsigned char)(data[0] & 0xff);
    if (negMantissa == 0)
    {
        // positive 2s-complement number to positive IEEE number.
        value = (((exponent + 0x7F) << 23) | mantissa) & 0x7fffffff;
        printf("a= %d\n",value);
    }
    else if (mantissa != 0)
    {
        // negative 2s-complement numbers with no zero fractions to same IEEE number.
        value = ((~mantissa) + 1) & 0x7fffff;
        value |= 0x80000000 | ((exponent + 0x7f) << 23);
        printf("b= %d",value);
    }
    else
    {
        // negative 2s-complement numbers with a 0 fraction.
        value = 0x80000000 | ((exponent + 0x80) << 23);
        printf("c= %d",value);
    }
    
    // Convert to float w/o modifying bits
    ret = *(float*)&value;
    //printf("Hello world!/n/t");
    printf("ret = %f\n",ret);
    return(0);
}