I have a 32bit number (unsigned int), I want to set another 32bit number to only a certain series of bits. For instance:
1000 0000 1011 1010 0111 1001 1101 0011 is what is given.
I want to set another number to bits 3 - 16 from the left, so bits 17 - 30.
I tried newNum = (given & 0x3FFF0000) but it is incorrect.
1000 0000 1011 1010 0111 1001 1101 0011given
0011 1111 1111 1111 0000 0000 0000 0000mask
---------------------------------------------------------------
The correct answer is 0000 0000 1011 1010 0000 0000 0000 0000
What am I doing wrong?
1000 0000 1011 1010 0111 1001 1101 0011 is what is given.
I want to set another number to bits 3 - 16 from the left, so bits 17 - 30.
I tried newNum = (given & 0x3FFF0000) but it is incorrect.
1000 0000 1011 1010 0111 1001 1101 0011given
0011 1111 1111 1111 0000 0000 0000 0000mask
---------------------------------------------------------------
The correct answer is 0000 0000 1011 1010 0000 0000 0000 0000
What am I doing wrong?
Comment