Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the value of x at the end?

uint8_t x = 0x5A;
x &= 0x0F;
x |= 0x80;

  • A.0x8F
  • B.0x8A
  • C.0x5A
  • D.0x0A

Answer: B

Correct answer: 0x8A

\( 0x5A \) is 0101 1010. Masking with \( 0x0F \) keeps the low nibble, giving 0000 1010, or \( 0x0A \). Setting the top bit with \( 0x80 \) gives 1000 1010, or \( 0x8A \). The two operations are the standard idioms: AND with a mask to keep bits, OR with a mask to set them.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.