Logo
All chapters
Volume II: Digital Logic  ›  Digital Systems & Binary Numbers

Binary Codes

Different ways to map information — digits, letters, states — onto bit patterns.

PrevSigned Binary Numbers
NextBinary Storage & Registers

Description

Agreed mappings between real-world symbols and binary patterns. Raw binary is just numbers; codes give those numbers meaning (a letter, a digit, a state). Define a table mapping each symbol to a unique bit pattern with useful properties.

  • Each decimal digit is encoded in its own 4-bit group (0000–1001).
  • Easy decimal display, but wastes 6 of 16 codes per digit.
  • Consecutive values differ in exactly one bit.
  • Prevents multi-bit glitches in encoders and K-map adjacency.
  • ASCII encodes characters in 7 bits (128 symbols).
  • Unicode extends this to cover all writing systems.
  • What: Agreed mappings between real-world symbols and binary patterns.
  • Why: Raw binary is just numbers; codes give those numbers meaning (a letter, a digit, a state).
  • How: Define a table mapping each symbol to a unique bit pattern with useful properties.
  • Where: Keyboards/displays (ASCII), digital meters (BCD), rotary encoders (Gray code).

At a glance

What

Agreed mappings between real-world symbols and binary patterns.

Why

Raw binary is just numbers; codes give those numbers meaning (a letter, a digit, a state).

How

Define a table mapping each symbol to a unique bit pattern with useful properties.

Where

Keyboards/displays (ASCII), digital meters (BCD), rotary encoders (Gray code).

When

Whenever non-numeric or specially-structured data must be stored in bits.

Think of it like…

Codes are like different alphabets for the same idea: BCD spells each decimal digit separately (like writing numbers digit-by-digit), Gray code is a careful walk where you change one footstep at a time so you never trip.

BCD (binary-coded decimal)

  • Each decimal digit is encoded in its own 4-bit group (0000–1001).
  • Easy decimal display, but wastes 6 of 16 codes per digit.

Gray code

  • Consecutive values differ in exactly one bit.
  • Prevents multi-bit glitches in encoders and K-map adjacency.

ASCII / Unicode

  • ASCII encodes characters in 7 bits (128 symbols).
  • Unicode extends this to cover all writing systems.

Decimal · BCD · Gray (0–7)

DecimalBinaryBCDGray
00000000000
10010001001
20100010011
30110011010
41000100110
51010101111
61100110101
71110111100

Note how each Gray row differs from its neighbor in a single bit.

The 5 Whys

  1. 1

    Why have multiple codes? Different jobs need different bit-pattern properties.

  2. 2

    Why BCD? To display decimal digits without binary-to-decimal conversion.

  3. 3

    Why Gray code? To avoid transient wrong values when several bits change at once.

  4. 4

    Why ASCII? To agree on one mapping so text is portable between machines.

  5. 5

    Root cause: encoding choice shapes error behavior, hardware cost, and interoperability.

Cheat sheet

Working principle

  • Define a table mapping each symbol to a unique bit pattern with useful properties.
  • Agreed mappings between real-world symbols and binary patterns.

Key facts

  • Each decimal digit is encoded in its own 4-bit group (0000–1001).
  • Consecutive values differ in exactly one bit.
  • ASCII encodes characters in 7 bits (128 symbols).

Why it exists

  • Root cause: encoding choice shapes error behavior, hardware cost, and interoperability.
PrevSigned Binary Numbers
NextBinary Storage & Registers