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

Discussion

If a variable can take only integral values from 0 to n. where n is a constant integer, then the variable can be represented as a bit-field whose width is the integral part of (the log in the answers arc to the base 2)

  • A.log (n) + 1
  • B.log (n - 1) + 1
  • C.log (n + 1) + 1
  • D.none of the above

Answer: A

Correct answer: log (n) + 1

To represent every value from 0 to \( n \) requires enough bits to express \( n \) itself, which takes \( \lfloor \log_2 n \rfloor + 1 \) bits.

Checking with \( n = 7 \): \( \lfloor \log_2 7 \rfloor + 1 = 2 + 1 = 3 \) bits, which gives the eight values 0 to 7 - correct. With \( n = 8 \) it gives \( 3 + 1 = 4 \) bits, since three would only reach 7. The other expressions fail one or other of these checks.

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

Post your comment

Please log in or register to post a comment.