constchar*sPlaceHolder ="This string is just a place holder for some value that can copied and placed into the text array/string so it can be further converted into uint32 values.";
uint32_t valueArray[FINAL_LENGTH]={0};// if you have 512 bytes of input to store and you want to store them in 4-byte chunks,
// then 512/4 = 128
int i;
for(i=0; i < TEXT_LENGTH; i++){
int mode = i %4;// 4-to-1 value storage ratio (4 uint8s being stored as 1 uint32)
int writeLocation =(int)(i/4);// values will be truncated, so something like 3/4 = 0 (which is desired)
switch(mode){
case(0):
// add to bottom 8-bits of index
valueArray[writeLocation]= text[i];
break;
case(1):
valueArray[writeLocation]|=(text[i]<<8);// shift to left by 8 bits to insert to second byte
break;
case(2):
valueArray[writeLocation]|=(text[i]<<16);// shift to left by 16 bits to insert to third byte
break;
case(3):
valueArray[writeLocation]|=(text[i]<<24);// shift to left by 24 bits to insert to fourth byte
break;
default:
printf("Some error occurred here... If source has been modified, please check to make sure the number of case handlers == the possible values for mode.\n");
}
}
// All done.
// valueArray[0] will now contain bytes as: text[4] text[3] text[2] text[1]
// ValueArray[1] will contain bytes as: text[8] text[7] text[6] text[5]
// ... etc... all the way through the indices
// do some processing on your array, but for this example, i'm just going to print out the values at each index of the array.
for(i=0; i < FINAL_LENGTH; i++){
printf("ValueArray[%d]: \t%zu\n", i, valueArray[i]);