So I’m trying to solve this problem:
You are given random 32bit positive integer, and what you have to do is swap the values of the bits on 3rd, 4th and 5th positions with those on 24th, 25th and 26th position.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that this is a problem for which you do not want an explicit solution, here is a hint: mask the bits in question using
&, do a shift, and thenORthen in using bitwise|.You can “cut out” bits 3, 4, and 5 using the
0x00000034mask, and bits 24, 25, and 26 using the0x07000000mask.Take a look at this solution to bit reversing problem for an inspiration.
EDIT : (in response to “not a homework” comment) Since this is not a homework, here is a more in-depth explanation: