Here's a more verbose way of creating the result you are looking for and code to test the operation.
#include <stdio.h>
void printBits(int n)
{
int i = 31;
char bits[32];
for ( ; i >= 0; --i, n /= 2 )
{
bits[i]= n % 2;
}
for ( i = 0; i < 32; ++i )
{
printf("%d", bits[i]);
if ( (i+1)%8 == 0 )
{
putchar(' ');
}
}
}
int foo(int n1, int n2)
{
// copy 8th and 9th bit of n1 to 2nd and 3rd bit of n2
// (all indices are 0 based).
// Extract the 8th and 9th bits of n1
int k1 = 0x00000300;
int r1 = n1 & k1;
// Clear the 2nd and 3rd bits of n2.
int k2 = 0xFFFFFFF9;
int r2 = n2 & k2;
// Move the 8th and 9th bits of n1 by 6 to the right
// to put them in 2nd and 3rd places.
// Construct the result and return.
return (r1 >> 6) | r2;
}
int main(int argc, char** argv)
{
int n1 = atoi(argv[1]);
int n2 = atoi(argv[2]);
printf("Input n1: ");
printBits(n1);
printf("\n");
printf("Input n2: ");
printBits(n2);
printf("\n");
int n3 = foo(n1, n2);
printf("Result : ");
printBits(n3);
printf("\n");
}
Sample output:
./test-19 251282 85
Input n1: 00000000 00000011 11010101 10010010
Input n2: 00000000 00000000 00000000 10000000
Result : 00000000 00000000 00000000 10000100