0
0
Embedded Cprogramming~10 mins

Endianness (big-endian vs little-endian) 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 define a 16-bit integer variable named value.

Embedded C
uint16_t [1] = 0x1234;
Drag options to blanks, or click blank then click option'
Aval
Bvalue
Cnum
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than 'value'.
2fill in blank
medium

Complete the code to create a pointer to the first byte of value.

Embedded C
uint8_t *ptr = (uint8_t *) &[1];
Drag options to blanks, or click blank then click option'
Avalue
Bnum
Cdata
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name other than 'value'.
3fill in blank
hard

Fix the error in the code to correctly print the first byte of value in hexadecimal.

Embedded C
printf("First byte: 0x%[1]\n", *ptr);
Drag options to blanks, or click blank then click option'
AX
Bx
Cd
Do
Attempts:
3 left
💡 Hint
Common Mistakes
Using decimal (%d) or octal (%o) format specifiers.
4fill in blank
hard

Fill the blank to create a function that checks if the system is little-endian.

Embedded C
int is_little_endian() {
    unsigned int num = 1;
    return *((unsigned char *) &num) [1] 1;
}
Drag options to blanks, or click blank then click option'
A<
B!=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using inequality or wrong comparison operators.
5fill in blank
hard

Fill all three blanks to create a function that swaps the byte order of a 16-bit integer.

Embedded C
uint16_t swap_bytes(uint16_t val) {
    return (val [1] 8) | ((val [2] 8) & [3] 0xFF00);
}
Drag options to blanks, or click blank then click option'
A<<
B>>
C&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong shift directions or missing masking.