liveBook · Manning

Encoding

As explained in Grokking Algorithms, Second Edition

A character encoding is a system that represents text characters as binary code values.

Character encoding is a system for representing text characters as binary code values. When a file contains four characters such as “tilt,” its size depends on the encoding used to represent those characters. section 7.6

A bit is either 0 or 1, and eight bits make one byte. With ISO-8859-1, each character uses one byte: the letter a is code 97, or 01100001 in binary. Eight bits provide 256 possible values, from 00000000 through 11111111. section 7.6

Representing a short file

The file “tilt” occupies 4 bytes under the simple one-byte-per-character example. A binary dump displays one byte for each character, making the storage representation visible. section 7.6

Encoding standards developed as limited character sets became impractical:

  • ASCII uses 7 bits and provides 128 characters, but omits characters such as ü, ö, £, and ¥. section 7.6
  • ISO-8859-1 uses 8 bits and expands the range to 256 characters, but still cannot represent every language. section 7.6
  • Unicode aims to provide characters for every language, while UTF-8 encodes Unicode characters using one to four bytes. section 7.6

Encoding choices involve a trade-off between simplicity, capacity, and compatibility. Fixed-width encodings make sizes predictable, while UTF-8 uses variable-length representations to support a much larger character set. section 7.6

How Grokking Algorithms, Second Edition covers it

How deep it goes
Defines bits and bytes, walks through ISO-8859-1, and contrasts ASCII, Unicode, and UTF-8 without developing decoding internals.
Examples
Uses the letter a, the word “tilt,” file-size output, and binary dumps to make encoding concrete.
What it assumes
Teaches binary digits and bytes from zero while assuming only familiarity with text characters and files.
What you can do after
Evaluate how ASCII, ISO-8859-1, Unicode, and UTF-8 represent characters and affect storage size.
How it connects
Connects character encoding with binary representation, ASCII, ISO-8859-1, Unicode, UTF-8, and Huffman coding.

Also explained in

Compare how 9 books explain encoding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Algorithms, Second Edition. The section links point to the parts of the book it draws on.