Q43 Write a C program to reverse odd bits or even bits of an integer.

You may also like...

2 Responses

  1. Avinash says:

    This is not reverse program it is inverting/flip of even and odd bits……….

  2. Avinash singh says:

    /* reverse even bits only without affecting even bits */
    #include
    int reverse(int);
    void displaybits(int);
    int main()
    {
    int a;
    printf(“enter Number\n”);
    scanf(“%i”,&a);
    displaybits(a);
    // printf(“%x”,reverse(a));
    displaybits(reverse(a));
    }

    int reverse(int a)
    {
    unsigned int reverse_num=0,i,temp;
    unsigned int odd_bits=a&0x55555555;
    unsigned int even_bits=a&0xAAAAAAAA;
    for(i=1;i<32;i=i+2)
    {
    temp=(a & (1<<i));
    // printf("temp:%d",temp);
    if(temp)
    reverse_num |= (1<0)
    {
    if(x & MASK)
    printf(“1”);
    else
    printf(“0″);
    printf(” “);
    MASK=MASK>>1;
    }
    printf(“\n”);

    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.