1

This question not probably not typical stackoverflow but am not sure where to ask this small question of mine.

Problem:

Find the number of bits in the binary representation of decimal number 16?

Now I tried to solve this one using the formula $2^n = 16 \Rightarrow n = 4$ but the correct answer as suggested by my module is 5. Could anybody explain how ?


After reading some answer,(and also I have 10 more mints before I could accept the correct answer)I think this is probably an explanation,that will be consistent to the mathematical formula,

For representing 16 we need to represent 17 symbols (0,16), hence $2^n = 17 \Rightarrow n = 4.08746$ but as n need to be an integer then $n = 5$

Halle
  • 3,584
  • 1
  • 37
  • 53
Quixotic
  • 2,424
  • 7
  • 36
  • 58
  • "the answer seems to be 5"? What does this mean? Could anybody explain? – S.Lott Dec 16 '10 at 11:29
  • I suppose you just need to understand that Ceil(log2(num)) gives you the number of bits required to express "num" numbers. Not the number "num". The difference is 1 :P – Noon Silk Dec 16 '10 at 12:06
  • How many digits do you need to express the decimal representation of 100? – Tom Anderson Apr 30 '12 at 22:00

4 Answers4

3

Think of how binary works:

Bit 1: Add 1
Bit 2: Add 2
Bit 3: Add 4
Bit 4: Add 8
Bit 5: Add 16

Thus 16 would be: 10000

Dark Falcon
  • 43,592
  • 5
  • 83
  • 98
2

With 4 bits, you can represent numbers from 0 to 15.

So yes, you need 5 bits to represent 16.

LaGrandMere
  • 10,265
  • 1
  • 33
  • 41
1
Decimal - 16 8 4 2 1
Binary -   1 0 0 0 0

So for anything up to decimal 31 you only need 5 bits.

Dave D
  • 8,472
  • 4
  • 33
  • 45
0

This is a classic fencepost error.

As you know, computers like to start counting from 0.

So to represent 16, you need bits 0, 1, 2, 3 and 4 (= floor(log2(16))).

But to actually contain bits 0 to 4, you need 5 bits.

Neil
  • 54,642
  • 8
  • 60
  • 72