Q:

C Program to reverse bits of an integer number

0

C Program to reverse bits of an integer number

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
unsigned int revBits(unsigned int data)
{
    unsigned char totalBits = sizeof(data) * 8;
    unsigned int revNum = 0, i, temp;
 
    for (i = 0; i < totalBits; i++)
    {
        temp = (data & (1 << i));
        if(temp)
            revNum |= (1 << ((totalBits - 1) - i));
    }
 
    return revNum;
}
 
 
int main()
{
    unsigned int num = 0x4;
    printf("\n%u", revBits(num));
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now