0
0
Cprogramming~20 mins

Bitwise NOT in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bitwise NOT Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this bitwise NOT operation?
Consider the following C code snippet. What will it print?
C
#include <stdio.h>

int main() {
    unsigned char x = 0b00001111; // 15 in decimal
    unsigned char y = ~x;
    printf("%u\n", y);
    return 0;
}
A240
B15
C0
D255
Attempts:
2 left
💡 Hint
Remember that bitwise NOT flips all bits. For an 8-bit unsigned char, 0b00001111 becomes 0b11110000.
Predict Output
intermediate
2:00remaining
What is the output of bitwise NOT on a signed integer?
What will this C program print?
C
#include <stdio.h>

int main() {
    int x = 0;
    int y = ~x;
    printf("%d\n", y);
    return 0;
}
A0
B-1
C1
D2147483647
Attempts:
2 left
💡 Hint
Bitwise NOT flips all bits. For zero, all bits flipped become all ones, which is -1 in two's complement.
🔧 Debug
advanced
2:00remaining
Why does this bitwise NOT code produce unexpected output?
This code is intended to print the maximum unsigned integer value after applying bitwise NOT to 0, but it prints -1 instead. Why?
C
#include <stdio.h>

int main() {
    unsigned int x = 0;
    unsigned int y = ~x;
    printf("%d\n", y);
    return 0;
}
AThe bitwise NOT operator (~) doesn't work correctly on unsigned integers.
BThere is integer overflow when applying ~ to 0.
CThe printf format specifier "%d" expects a signed int, and the bit pattern of UINT_MAX (all 1s) is interpreted as -1 in two's complement.
Dunsigned int y = ~x promotes x to signed before applying ~.
Attempts:
2 left
💡 Hint
The issue is with how printf interprets the unsigned value when using the wrong format specifier.
Predict Output
advanced
2:00remaining
What is the output of this bitwise NOT on a 16-bit unsigned short?
Given this C code, what will be printed?
C
#include <stdio.h>

int main() {
    unsigned short x = 0x00FF; // 255 decimal
    unsigned short y = ~x;
    printf("%u\n", y);
    return 0;
}
A65280
B255
C65535
D0
Attempts:
2 left
💡 Hint
Bitwise NOT flips all bits in 16 bits. 0x00FF flipped becomes 0xFF00.
Predict Output
expert
2:00remaining
What is the output of this bitwise NOT on a signed char with negative value?
Analyze this C code and determine what it prints.
C
#include <stdio.h>

int main() {
    signed char x = -1;
    signed char y = ~x;
    printf("%d\n", y);
    return 0;
}
A127
B-1
C-128
D0
Attempts:
2 left
💡 Hint
Bitwise NOT flips all bits. For -1 in two's complement, all bits are 1, flipping gives all 0 bits.