0
0
Embedded Cprogramming~20 mins

Fixed-width integers (uint8_t, uint16_t, uint32_t) in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fixed-width Integer Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of uint8_t overflow
What is the output of this C code snippet when using uint8_t for variable a?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint8_t a = 250;
    a += 10;
    printf("%u\n", a);
    return 0;
}
A4
B260
COverflow error at runtime
D10
Attempts:
2 left
💡 Hint
Remember that uint8_t can only hold values from 0 to 255 and wraps around on overflow.
Predict Output
intermediate
2:00remaining
Size of fixed-width integers
What is the output of this code printing the sizes of uint8_t, uint16_t, and uint32_t in bytes?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    printf("%zu %zu %zu\n", sizeof(uint8_t), sizeof(uint16_t), sizeof(uint32_t));
    return 0;
}
A8 16 32
B4 4 4
C1 2 4
DCompiler dependent, could be any values
Attempts:
2 left
💡 Hint
Fixed-width integers have sizes guaranteed by their names.
🔧 Debug
advanced
2:00remaining
Unexpected output due to integer promotion
This code intends to add two uint8_t variables and print the result. What is the output and why?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint8_t x = 200;
    uint8_t y = 100;
    uint8_t z = x + y;
    printf("%u\n", z);
    return 0;
}
ACompilation error
B300
COverflow error
D44
Attempts:
2 left
💡 Hint
Remember that arithmetic on small integer types is promoted to int before assignment.
🧠 Conceptual
advanced
1:30remaining
Range of uint16_t
What is the range of values that a uint16_t variable can hold?
A0 to 32767
B0 to 65535
C-32768 to 32767
D-65535 to 65535
Attempts:
2 left
💡 Hint
uint16_t is unsigned and 16 bits wide.
Predict Output
expert
2:30remaining
Bitwise operations on uint32_t
What is the output of this code snippet?
Embedded C
#include <stdio.h>
#include <stdint.h>

int main() {
    uint32_t a = 0xF0F0F0F0;
    uint32_t b = 0x0F0F0F0F;
    uint32_t c = (a & b) | (~a & b);
    printf("0x%X\n", c);
    return 0;
}
A0x0F0F0F0F
B0xFFFFFFFF
C0xF0F0F0F0
D0x00000000
Attempts:
2 left
💡 Hint
Simplify the expression using bitwise logic identities.