Ask Question

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.

+3
Answers (1)
  1. 25 December, 02:37
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers