It is difficult and difficult to flip the binary position of C language !!!

Source: Internet
Author: User

It is difficult and difficult to flip the binary position of C language !!!
Problem description: Write the function: unsigned int reverse_bit (unsigned int value); the value returned by this function is the value after the binary bit mode is flipped from left to right. For example, on a 32-bit machine, the value 25 contains the following: 00000000000000000000000000011001 after the flip: (2550136832) the result of the 10011000000000000000000000000000 program is returned: 2550136832 code implementation:

# Include <stdio. h> # include <math. h> unsigned int reverse_bit (unsigned int value) {int I = 0; unsigned int sum = 0; for (I = 0; I <32; I ++) {sum + = (value> I) & 1) * pow (2,31-i);} return sum;} int main () {unsigned int value = 25; // 00000000 00000000 00000000 00011001 int ret = reverse_bit (value); printf ("% u \ n", ret); return 0 ;}

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.