Ask Question
19 December, 00:48

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.

+1
Answers (1)
  1. 19 December, 03:30
    0
    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
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “2. Assuming that the bits in an integer are numbered from 0, from right (least significant) to left (most significant), write an expression ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers