UTF-16 (source code)
= UTF-16
{c}
{wiki}
<UTF-16> is a <Unicode> encoding form using sixteen-bit <code units>. A <Unicode scalar value> below `U+10000` uses one <code unit>; a larger one uses a <surrogate pair>. The surrogate range `D800`–`DFFF` is reserved for these pairs and does not itself contain <Unicode scalar values>.<The Unicode Standard Version 17 Core Specification>[§3.9.2, UTF-16 definition and surrogate-pair construction]{ref}
To encode `U+1F600`, subtract <hexadecimal> `10000`, obtaining `F600`. Split the result into two ten-bit pieces, `003D` and `0200`; adding `D800` and `DC00` respectively gives `D83D DE00`. One represented <code point> therefore occupies two <code units>. Counting or cutting sixteen-bit positions can split that pair, while a <grapheme cluster> can span several <code points>. The encoding form specifies these numerical units; serialization as <bytes> additionally requires a byte-order convention.
Back to article page