Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than 'value'.
✗ Incorrect
The variable is named value as required.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name other than 'value'.
✗ Incorrect
The pointer ptr points to the address of value.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using decimal (%d) or octal (%o) format specifiers.
✗ Incorrect
The format specifier %X prints the number in uppercase hexadecimal.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inequality or wrong comparison operators.
✗ Incorrect
The function returns true if the first byte equals 1, indicating little-endian.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong shift directions or missing masking.
✗ Incorrect
The function shifts the upper byte right and the lower byte left, then masks the upper byte.