HackerRank: Flipping bits of an unsigned Integer Solution in C

You will be given a list of 32-bit unsigned integers. Flip all the bits (1 to 0) and 0 to 1 and return the result as an unsigned integer.

long flippingBits(long n) {
    int len = sizeof(long) * 8;
    int i=0;
    printf("%d\n",  len);
        int flag = (n&1<<i);
        if (flag) n &= ~(1<<i);
        else n |= (1<<i);
    } */
    return (pow(2,32)-1) - n;
    //return n;

Leave a Comment