C Language of bits flip, difficult difficult!!!

Source: Internet
Author: User

Problem Description:


To write a function:
unsigned int reverse_bit (unsigned int value);
The return value of this function values the value of the BITS mode from left to right.

Such as:
On 32-bit machines 25 This value contains the following members:
00000000000000000000000000011001
After flipping: (2550136832)
10011000000000000000000000000000
The program results return:
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); r Eturn 0;}

The result is: 2550136832. 10011000 00000000 00000000 00000000

This article is from the "Pzd Chuan Feng" blog, please make sure to keep this source http://xujiafan.blog.51cto.com/10778767/1711236

C Language of bits flip, difficult difficult!!!

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.