4byte to integer

Hi, I guess this is an quite simple question, but I wasn't able to find a solution for this problem using Google (: I simply don't know WHAT I need to search for.

Let's say you wrote "aBcd" to a text-file and now you convert those ASCII chars to hex and combine them (little endian / big endian) to one integer value.
How to solve this problem? Is there any function in C++ that's able to handle this problem?

It would be great if you could tell me, and also I would like to know to do vice versa.

Hope you understood what I mean. My English isn't very well.
closed account (o3hC5Di1)
Hello there,

I think this might be what you need to get started:
http://www.cplusplus.com/forum/beginner/11401/

Hope that helps.

All the best,
NwN
Well ok, now I know I'm able to convert an ASCII char to a number simple using (int)c, but I still need to know how to combine 4 bytes to one big number..
So now my program could be able to get the following values: a->97 , B-> 66, c->99, d->100. How to do the next step and calculate those to one 32bit int?
By using bit shifting and bitwise or:
1
2
3
4
const char* str="aBcd";
const int nBytes=4;
uint32_t combinedInteger=0;
for (int i=0;i<nBytes;i++)combinedInteger|=static_cast<unsigned char>(str[i])<<(i*8);
Topic archived. No new replies allowed.