Q:

Concatenating bits

I have have to concatenate the bits of the int. For example:
unsigned char byte1 = 0x0F;   // 00001111
unsigned char byte2 = 0xCC;   // 11001100
unsigned char byte3 = 0x55;   // 01010101
unsigned char byte4 = 0x04;   // 00000100

After concatenation the result should be:
00000100010101011100110000001111 

I tried doing smth like:
unsigned int temp = 0;
temp = temp | byte1; //the result should be 00001111 for now

temp = temp >> 8;
byte2 = byte2 << 8;
temp = temp | byte2; //the result should be 1100110000001111 for now

temp = temp >> 8;
byte3 = byte3 << 8;
temp = temp | byte3; //the result should be 010101011100110000001111 for now

temp = temp >> 8;
byte4 = byte4 << 8;
temp = temp | byte4; //the result should be 00000100010101011100110000001111

But when I print the temp, it shows 0:
printf("%d", temp) //===> gives 0

A:

Actually it seems to me the 
temp = temp >> 8;

bitshifts away your entire temp value.

A:

unsigned int byte1 = 0x0F; // 00001111; //byte1
unsigned int byte2 = 0xCC; // 11001100; //byte2
unsigned int byte3 = 0x55; // 01010101; //byte3
unsigned int byte4 = 0x04; // 00000100; //byte4

unsigned int temp = (byte1) | (byte2 << 8) | (byte3 << 16) | (byte4 << 24);
printf("%u", temp);

prints 72731663 which is 00000100010101011100110000001111.

If you want to keep your inputs as unsigned char, then this has the same result:
unsigned char byte1 = 0x0F; // 00001111; //byte1
unsigned char byte2 = 0xCC; // 11001100; //byte2
unsigned char byte3 = 0x55; // 01010101; //byte3
unsigned char byte4 = 0x04; // 00000100; //byte4

unsigned int temp = byte4;
temp <<= 8;
temp |= byte3;
temp <<= 8;
temp |= byte2;
temp <<= 8;
temp |= byte1;
printf("%u", temp);

