2. Assuming that the bits in an integer are numbered from 0, from right (least significant) to left (most significant), write an expression using bitwise logical operators to extract the 4 bits numbered 6 to 3 from an integer i1, and shift them all down so that bit numbered 3 ends up in position number 1.

Respuesta :

Answer:

Explanation:

Two ways of interpreting this question

(I) Shifting all the bits along with the choosen four,

in that case it will be i1>>2;

(ii) Just shifting the choosen four bits and keeping the remaining as it is.

It is equivalent to replacing the first four bits of i1 with i1>>2. let us call N = i1, and M = i1>>2.

max = ~0 //All one's

//1's through position 4, then all zeros

left = max - ((1<<4) - 1);

So we just have zeros between bits one to four and other are one.

Now final step;

(N&left) | m