我使用下面的代码来获取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下面是我的完整代码:
发布于 2018-09-10 06:33:00
0000010000000000是一个八进制文字,而不是二进制文字,请使用十六进制的0x0400。
发布于 2018-09-10 12:16:56
在标准C中没有二进制常量,所以你不能有像0b0000010000000000这样的常量。但GCC有一个extension,可以用0b或0B前缀来支持它们。
如果你不是在使用GCC,那么最好遵循@zch提供的建议。
https://stackoverflow.com/questions/52249083
复制相似问题