100 topics · Read, check sources and follow your curiosity.

A little room to wonder

Binary & Digital Data

Bits represent two states. Positional binary uses those states to represent numbers, while an encoding rule gives bit patterns other meanings.

How can the same bit pattern mean a number, a letter or part of an image?

A grey punched-card sorting machine stands above compartments holding paper cards.
Punched-card equipment is a historical example of information represented physically. The card positions in this photograph should not be read as the five-bit place-value example without their actual encoding key.waelder · Source · CC BY 2.5

Two states can be represented physically

A bit has two possible values, conventionally written 0 and 1. Different physical systems can represent them using distinguishable states. The written digits are a notation, not tiny symbols that must be printed inside a computer.

Several bits create more possible patterns. Two bits have four patterns: 00, 01, 10 and 11. Add one bit and each previous pattern can end in either 0 or 1, doubling the possibilities. Five bits therefore have 32 patterns.

Place value supplies a number rule

In ordinary decimal notation, columns represent ones, tens, hundreds and so on. In unsigned positional binary, the columns represent powers of two. Reading five columns from left to right gives 16, 8, 4, 2 and 1. A 1 includes that column’s value and a 0 leaves it out.

With five bits, the largest unsigned value is 16 + 8 + 4 + 2 + 1 = 31. The 32 patterns represent values from 0 through 31, including zero. “32 patterns” does not mean the largest value is 32.

Worked example: encode and check 22

To represent decimal 22, start with 16 and find the remainder: 22 − 16 = 6. Do not include 8 because it is larger than the remainder. Include 4, leaving 2; include 2, leaving 0; leave out 1. The five columns read 1, 0, 1, 1, 0, or 10110.

Decode it independently: 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 22. This reverse check catches a misplaced digit. If a sixth leading zero is added, 010110 still has unsigned value 22; a different encoding rule could treat the same sequence differently.

The key determines the meaning

Under a tiny invented letter code, 00 could mean A, 01 mean B, 10 mean C and 11 mean D. Under an unsigned number rule, 10 means decimal 2 instead. Neither interpretation can be chosen just by looking at the two symbols; you need the agreed encoding.

Real text, images and sound use more elaborate formats. A file also needs information about how its bits are organised. Binary does not make data automatically private or correct: an unintended bit change can alter a value while still leaving a valid-looking pattern.

Only if you feel like trying

Encode, then decode independently

  1. Use the five column values 16, 8, 4, 2 and 1 to encode decimal 13.
  2. Decode your pattern from the column values. The check should give 8 + 4 + 1 = 13.
  3. Write the invented two-bit A–D key and explain why 10 needs that key before it can mean C.

Optional. Work on paper, point to the example or talk it through. No account, purchase or public sharing is needed.