0
0
Embedded Cprogramming~10 mins

Bit field structures in Embedded C - Interactive Code Practice

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

Complete the code to declare a bit field of 3 bits named 'flag'.

Embedded C
struct Status {
    unsigned int flag : [1];
};
Drag options to blanks, or click blank then click option'
A3
B5
C8
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number larger than the type size.
Forgetting the colon ':' after the field name.
2fill in blank
medium

Complete the code to declare a bit field named 'mode' with 2 bits inside the struct.

Embedded C
struct Control {
    unsigned int [1] : 2;
};
Drag options to blanks, or click blank then click option'
Amode
Bstatus
Cflag
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong field name.
Omitting the bit size after the colon.
3fill in blank
hard

Fix the error in the bit field declaration to make it valid C code.

Embedded C
struct Flags {
    unsigned int error [1] 1;
};
Drag options to blanks, or click blank then click option'
A,
B:
C;
D.
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semicolon or comma instead of a colon.
Missing the colon entirely.
4fill in blank
hard

Fill both blanks to declare a struct with two bit fields: 'ready' (1 bit) and 'error' (2 bits).

Embedded C
struct Status {
    unsigned int [1] : 1;
    unsigned int [2] : 2;
};
Drag options to blanks, or click blank then click option'
Aready
Bflag
Cerror
Dstate
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the field names.
Using incorrect bit sizes.
5fill in blank
hard

Fill all three blanks to create a bit field struct with fields: 'mode' (3 bits), 'status' (4 bits), and 'flag' (1 bit).

Embedded C
struct Device {
    unsigned int [1] : 3;
    unsigned int [2] : 4;
    unsigned int [3] : 1;
};
Drag options to blanks, or click blank then click option'
Aflag
Bstatus
Dmode
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of fields.
Using the wrong field names for the bit sizes.