我有这段代码用于获取 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
这是我的完整代码:
最佳答案
0000010000000000
是八进制,不是二进制,使用十六进制 0x0400
。
关于c - 顽固的位不会被设置为一个。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52249083/