[英]Floating Point representation in Binary
I'm trying to print the a number stored in floating point in C and I'm struggling how to print it out.我正在尝试打印存储在 C 中的浮点数中的数字,但我正在努力将其打印出来。 I'm doing this right now which prints the number in IEEE format.我现在正在这样做,以 IEEE 格式打印数字。 I want it printed in reverse straight from memory.我希望它直接从记忆中反向打印。 How can I fix it?我该如何解决? Thanks谢谢
void printbits(size_t n, void *c) {
unsigned char *t = c;
if (c == NULL)
return;
while (n > 0) {
int q;
--n;
for(q = 0x80; q; q >>= 1)
printf("%x", !!(t[n] & q));
}
}
Use a union:使用联合:
union u {
float f;
unsigned char p[4];
}
Then uf = myfloat;
然后uf = myfloat;
and iterate on up
并反覆up
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.