顽固的位不会被设置为一个。

Stubborn bit won't be set to one.

我有这段代码用于获取 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

这是我的完整代码:

https://pastebin.com/w4UVzmUe

0000010000000000是八进制,不是二进制,用十六进制0x0400.

标准 C 中没有二进制常量。所以你不能有像 0b0000010000000000 这样的东西。但是 GCC 有一个 extension 来支持带有 0b0B 前缀的它们。

如果你没有使用 GCC,那么最好使用 @zch 提供的建议。