Text Encoding (ASCII and Unicode)

Context: FIT1047_MOC · characters become numbers become bits · ASCII (1967) → Unicode codepoints → UTF-8/UTF-16 transfer formats

Quick Revision

  • 🎯 Objective: text = a sequence of encoded characters; decode hex bytes ↔ characters via the ASCII table.
  • ⚡ Key Constraint: ASCII is bits ( originally for error detection) ⟹ max 128 chars; extended 8-bit sets cap at 256 — hence Unicode.

📝 Core

  • ASCII (1967) ➔ maps English letters, digits , symbols into a 7-bit code; the 8th bit originally did simple error detection. Example: J .
  • Text as bytes ➔ simplest form is a plain sequence of codes: 61 20 73 65 71 … decodes to “a sequence of encoded characters”.
  • Extended ASCII ➔ 8th bit repurposed ⟹ 256-char “extended sets” for some European characters — still hopeless for languages with tens of thousands of characters.
  • Unicode ➔ assigns each character a codepoint in ⟹ over a million characters; codepoint ≠ byte encoding.
  • UTF-8 ➔ encodes each codepoint in 1–4 bytes; ASCII characters keep their single ASCII byte ⟹ every ASCII file is already valid UTF-8; dominant on the Internet.
  • UTF-16 ➔ exactly two bytes per codepoint ⟹ limited to the first codepoints.

⚠️ Common Mistakes

  • 💡 Codepoint vs encoding ➔ Unicode assigns numbers; UTF-8/UTF-16 decide the bytes — “Unicode is 2 bytes” conflates the two.
  • 💡 UTF-8 is variable-length ➔ byte count ≠ character count; slicing bytes mid-character corrupts text.

🧠 Active Recall