本文介绍了对于一些重新presentation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何找到适合的系统,我就数重新presentation?
How do I find the representation of a Number for the system I am on?
推荐答案
如再presentation(字的大小,two's-与补码与符号 - 幅度)和字节顺序建筑的问题最好用硬件回答和/或操作系统和/或编译器文档。
Architectural questions such as representation (word size, two's- vs. one's-complement vs. sign-magnitude) and endianness are best answered with hardware and/or OS and/or compiler documentation.
您可以使用双关语的类型来检查一个值的单个字节:
You can use type punning to examine the individual bytes of a value:
T value = ...; // for some numeric type T (int, short, long, double, float, etc.)
unsigned char *p = (unsigned char*) &value;
size_t i;
printf("%10s%8s\n", "address", "value");
printf("%10s%8s\n", "-------", "-----");
for (i = 0; i < sizeof value; i++)
printf("%10p%8x\n", p+i, (unsigned int) p[i]);
有关大端与小端,你可以不喜欢
For big- vs. little-endian, you could do something like
unsigned int value = 0x01;
unsigned char *p = (unsigned char *) &value;
if (p[0] == 1)
printf("Little-endian\n");
else if (p[sizeof value - 1] == 1)
printf("Big-endian\n");
else
printf("Weird\n");
更好地RTM,虽然。
Better to RTM, though.
这篇关于对于一些重新presentation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!