C 顽固的比特赢了';不要设为一。

C 顽固的比特赢了';不要设为一。,c,binary,ieee-754,ieee,C,Binary,Ieee 754,Ieee,我有一段代码,用来获取IEEE二进制数的尾数或值 iFloat_t floatGetVal (iFloat_t x) { iFloat_t mantissa = (BITS == 16) ? (x & 0x03FF) : (x & 0x007FFFFF); debug("%s: getVal before implicit 1", getBinary(mantissa)); //mantissa = (BITS ==

我有一段代码,用来获取IEEE二进制数的尾数或值

iFloat_t floatGetVal (iFloat_t x) {
  iFloat_t mantissa = (BITS == 16) ? (x & 0x03FF)
                      : (x & 0x007FFFFF);
    debug("%s: getVal before implicit 1", getBinary(mantissa));
    //mantissa = (BITS == 16) ? (mantissa | 0x04)
    //                : (mantissa | 0x008);
    mantissa = x | 0000010000000000;
    debug("%s: getVal after implicit 1", getBinary(mantissa));
    mantissa = (BITS == 16) ? (mantissa & 0x07FF)
                      : (mantissa & 0x00FFFFFF);
    if(floatGetSign(x) == 1) {
        mantissa = ~mantissa + 1;
    }
    return mantissa;
}
我的问题是,当我试图从数字63.125中获取值时,相应的输出如下:

DEBUG iFloat.c[31] floatGetVal() 0000-0011-1110-0100: getVal before implicit 1
DEBUG iFloat.c[35] floatGetVal() 0101-0011-1110-0100: getVal after implicit 1
DEBUG iFloat.c[81] floatAdd() 0000-0011-1110-0100: bits of val_y after assignment
这是我的预期输出:

DEBUG iFloat.c[31] floatGetVal() 0000-0011-1110-0100: getVal before implicit 1
DEBUG iFloat.c[35] floatGetVal() 0101-0111-1110-0100: getVal after implicit 1
DEBUG iFloat.c[81] floatAdd() 0000-0111-1110-0100: bits of val_y after assignment
这是我的全部代码:


000001000000000
是一个八进制文字,而不是二进制文字,请使用十六进制
0x0400
标准C中没有二进制常量。因此不能使用类似于
0B00000000000000000
的内容。但是GCC有一个支持它们的前缀
0b
0b

如果您不使用GCC,那么最好使用@zch提供的建议