Possible Duplicate:
Store an int in a char array?
i want to load 4 8-bit unsigned char to 32-bit integer. And store 32 bit integer to unsigned char pointer. How is this possible?Example usage below;
int 32bitint1= 0xff000000 | (uchar1<<16) | (uchar2<<8) | uchar3;
int 32bitint2= 0xff000000 | (uchar4<<16) | (uchar5<<8) | uchar6;
//then this 32-bit integer to uchar pointer;
ucharpointer[0] = 32bitint1;
ucharpointer[4] = 32bitint2;//is this possible?or how
Store: (store 4 chars into an unsigned int)
Load: (load 4 chars from an unsigned int)
Usage example:
If you don’t want to reload them into a char array, but to access them by a char pointer, then here’s an example:
Please note that the you will get an output ‘dcba’ in this way, as the memory address are made in the reverse order.