[英]Converting Char array to int/double/float
Thx for the help but maybe I should clarify my problem. 谢谢你的帮助,但也许我应该澄清我的问题。 I want to read some addresses from a text file, for instance: 我想从文本文件中读取一些地址,例如:
someFile:: 0xc4fap4424ab1 0xac8374ce93ac ... etc someFile :: 0xc4fap4424ab1 0xac8374ce93ac ...等
Now I want to take these addresses and convert them to decimal so that I can make address comparisons. 现在,我想获取这些地址并将其转换为十进制,以便进行地址比较。 So my question is 1. How should I go about storing these addresses 2. Once I have stored the addresses, how can I convert them to decimal. 所以我的问题是1.如何存储这些地址2.存储地址后,如何将其转换为十进制。
Your initializer declares just one element for the temp
array, and that value is way beyond the capacity of a char
. 您的初始化程序只为temp
数组声明一个元素,并且该值远远超出char
的能力。 The maximum value that you can store in a single char
is 0xFF
. 您可以存储在单个char
的最大值为0xFF
。
If temp
was something in the form of: 如果temp
的形式为:
char temp[] = {0x12, 0x34, 0x56, 0x78};
Then you could do some bit twiddling to produce an int
out of the 4 bytes. 然后,您可以进行一些调整以从4个字节中产生一个int
。 Actually I would use uint32_t
to be platform-independent: 实际上,我将使用uint32_t
来独立于平台:
uint32_t x = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3];
Of course, you have to take care of the endianness as well. 当然,您还必须注意字节顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.