liveBook · Manning

Code unit

A code unit is a fixed-size numeric unit used by a character encoding to represent text, such as a 16-bit unit in UTF-16.

How 2 Manning books explain it

JavaScript in Depth

A 16-bit unit of storage used by UTF-16 to encode Unicode text.

How it is used
Explains why UTF-16 storage units do not always correspond one-to-one with Unicode codepoints.
How deep it goes
Defines the 16-bit unit and works through one- versus two-unit encoding and surrogate-pair calculation.
Examples
Uses the UTF-16 encoding of `hello`, a surrogate-pair calculation, and regex matches against `😀ABC`.
What you can do after
Diagnose/debug with it when surrogate pairs make default and Unicode-aware regex matches differ.

Read how JavaScript in Depth explains code unit →

Julia as a Second Language

A code unit is a fixed-size storage unit used by an encoding to represent a Unicode code point in memory.

How it is used
Clarifies why Unicode characters and Julia string indices do not always correspond one-to-one.
How deep it goes
Defines the code-point distinction, demonstrates variable counts, and shows code-unit-aware indexing without fully deriving UTF-8 decoding.
Examples
Uses A, Æ, 😏, and Þrúðvangar to compare code-unit counts and character-boundary indices.
What you can do after
Evaluate code points and code-unit counts, then iterate through Julia strings using character-aware indices.

Read how Julia as a Second Language explains code unit →

Related concepts

Questions about code unit

What is code unit?

A code unit is a fixed-size numeric unit used by a character encoding to represent text, such as a 16-bit unit in UTF-16.

Which Manning books explain code unit?

JavaScript in Depth and Julia as a Second Language.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.