0
0
Embedded Cprogramming~10 mins

Signed vs unsigned behavior on 8-bit MCU in Embedded C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an 8-bit unsigned variable.

Embedded C
unsigned char [1] = 255;
Drag options to blanks, or click blank then click option'
Anum
Bvalue
Ccount
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using a signed type instead of unsigned.
Choosing a variable name that is not descriptive.
2fill in blank
medium

Complete the code to assign a negative value to a signed 8-bit variable.

Embedded C
signed char [1] = -128;
Drag options to blanks, or click blank then click option'
Adata
Btemp
Cval
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsigned char for negative values.
Assigning values outside the range -128 to 127.
3fill in blank
hard

Fix the error in the code to correctly add two unsigned 8-bit variables without overflow.

Embedded C
unsigned char a = 200;
unsigned char b = 100;
unsigned int sum = a [1] b;
Drag options to blanks, or click blank then click option'
A-
B*
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Storing the result in an 8-bit variable causing overflow.
4fill in blank
hard

Fill in the blank to correctly check if a signed 8-bit variable is negative.

Embedded C
signed char x = -5;
if (x [1] 0) {
    // x is negative
}
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < for negative check.
Using wrong operators like == or !=.
5fill in blank
hard

Fill all three blanks to create a loop that counts down an unsigned 8-bit variable from 10 to 0.

Embedded C
unsigned char i = [1];
while (i [2] 0) {
    // do something
    i [3] 1;
}
Drag options to blanks, or click blank then click option'
A10
B>
C-=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the loop condition.
Using ++ instead of -= to decrement.