Bitwise Operator Question

  1. Consider int val=0xFACE; Write expressions using bitwise operators that do the following:
    A. test if atleast three of the last four bits (LSB) are on
    B. reverse the byte order (i.e., produce val=0xCEFA)
    C. rotate four bits (i.e., produce val=0xEFAC)
  1. store each of the last bits by n&1 then shifting right by n>>1
  2. store the last bit, right shift n, create a mask of lastbit<<31 or this with n
  3. step 1:
    extract lsb, store it in variable x,
    initialise mask as x, (only for first time)
    in each consequent iteration
    left shift mask and or with x
    right shit n
    repeat this four times
    next step:
    left shift n by 4
    or with mask

hey @nimishbajaj0508 if your doubt is solved, please mark it as resolved

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.