Matrimony OTT-Platforms Jobs Coupons Business

C Program to Reverse all the Bits of an 32-bit Integer using Bitwise

/*
 * C Program to Reverse all the Bits of an 32-bit Integer using
 * Bitwise
 */
#include <stdio.h>
#define NUM_BITS_INT sizeof(int)*8

void main()
{
    unsigned int number;
    int i = 0, hexadecimal, rev = 0, bit;

    printf("enter the hexdecimal value\n");
    scanf("0x%number", &hexadecimal);
    while (i++ < NUM_BITS_INT)
    {
        bit = hexadecimal & 1;
        hexadecimal = hexadecimal >> 1;
        rev = rev ^ bit;
        if (i < NUM_BITS_INT)
            rev = rev << 1;
    }
    printf("reverse of hexadecimal value is 0x%number", rev);
}

OUTPUT
enter the hexdecimal value
0x01234567
reverse of hexadecimal value is 0xe6a2c480
Next Post Previous Post
No Comment
Add Comment
comment url
We detected that you're using an AdBlocker. Please disable it and refresh to continue using our website.
Ad