I want reverse the binary
unsigned short gf_t = 44 // = 00101100
in 00110100 in C language. How i will able to for that using bitwise operators?
pdta: My computer have 32 bits pattern.
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.
When in doubt, see the Bit Twiddling Hacks page. In fact, there you can find a very simple algorithm that does what you want…
There is also, however, several nifty approaches documented there. You can look into those and try to understand them for learning 🙂 For example, here is one particular interesting form…
Note that if
sizeof(unsigned short) * CHAR_BITis16, the appropriate usage would only require the first 4 transpositions — see as follows:That being said, why not just use
uint16_t(if it’s available)?Here is working example (see ideone):