开发者

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

Now I want to take these addresses and convert them to d开发者_Python百科ecimal 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.


Your initializer declares just one element for the temp array, and that value is way beyond the capacity of a char. The maximum value that you can store in a single char is 0xFF.

If temp was something in the form of:

char temp[] = {0x12, 0x34, 0x56, 0x78};

Then you could do some bit twiddling to produce an int out of the 4 bytes. Actually I would use uint32_t to be platform-independent:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜