Is decimal number 8 represented as 3 bits or 4 bits in computer?
$b$ bits have a total of $2^b$  distinct bit-patterns. To store 8 distinct values, you need at least 3 bits.

This does not tell you on its own how many bits are required to store the number 8, because it depends on the way that you assign numbers to bit patterns.

A typical "unsigned integer" uses $b$ bits to represent the numbers 0, 1, ... 2^b-1. In that format, you would need 4 bits to represent 8, because $2^3-1&lt;8&lt;2^4-1$.

A typical "two's complement integer" uses $b$ bits to represent the numbers $-2^{b-1}$ to $2^{b-1}-1$. In this format, you would need 5 bits to represent 8, since $2^{4-1}-1&lt;8&lt;2^{5-1}-1$.

If you're only interested in representing powers of two (perhaps because you doing something hardware or memory related, where divisions such as alignment are only ever powers of two), you use fewer bits; for example, if 00 is 1, 01 is 2, 10 is 4, and 11 is 8, you only need 2 bits to represent 8.