0
0
Embedded Cprogramming~20 mins

NOT for inverting bits in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bitwise Mastery
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 be printed when it runs?
Embedded C
#include <stdio.h>

int main() {
    unsigned char x = 0b10101010;
    unsigned char y = ~x;
    printf("%u\n", y);
    return 0;
}
A255
B170
C0
D85
Attempts:
2 left
💡 Hint
Remember that ~ flips all bits, and unsigned char is 8 bits.
Predict Output
intermediate
2:00remaining
What is the output when applying NOT to a signed integer?
Look at this C code. What will it print?
Embedded C
#include <stdio.h>

int main() {
    int x = 0;
    int y = ~x;
    printf("%d\n", y);
    return 0;
}
A1
B0
C-1
D2147483647
Attempts:
2 left
💡 Hint
Think about how ~ works on zero in two's complement.
Predict Output
advanced
2:00remaining
What is the output of this NOT operation on a 16-bit unsigned short?
Given this code, what will be printed?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint16_t x = 0x00FF;
    uint16_t y = ~x;
    printf("0x%04X\n", y);
    return 0;
}
A0xFF00
B0x00FF
C0xFFFF
D0x0000
Attempts:
2 left
💡 Hint
NOT flips all bits in the 16-bit number.
Predict Output
advanced
2:00remaining
What is the output of this NOT operation on a signed char with value -1?
Analyze this code and determine the output.
Embedded C
#include <stdio.h>

int main() {
    signed char x = -1;
    signed char y = ~x;
    printf("%d\n", y);
    return 0;
}
A0
B-128
C127
D-1
Attempts:
2 left
💡 Hint
Remember that -1 in two's complement is all bits set to 1.
🧠 Conceptual
expert
3:00remaining
Why does using NOT (~) not always simply invert bits in embedded C?
Which statement best explains why applying the NOT operator (~) in embedded C might not always produce a simple bit inversion effect?
ABecause the NOT operator only works on unsigned types and causes errors on signed types.
BBecause the size of the data type affects how many bits are inverted, and sign extension can change the result.
CBecause the NOT operator shifts bits instead of inverting them in embedded C.
DBecause the NOT operator converts numbers to floating point before inverting bits.
Attempts:
2 left
💡 Hint
Think about how data types and sign affect bitwise operations.