Par sustituto

Encoding & Standards

Dos unidades de código UTF-16 (un sustituto alto U+D800–U+DBFF seguido de un sustituto bajo U+DC00–U+DFFF) que juntas representan un carácter superior a U+FFFF.

Characters with code points above U+FFFF cannot fit in a single 16-bit value. UTF-16 solves this by encoding them as two 16-bit values called a surrogate pair. Since most emoji are above U+FFFF, surrogate pairs are extremely common with emoji.

For example, 😀 (U+1F600) becomes the surrogate pair 0xD83D 0xDE00 in UTF-16. The formula: high surrogate = 0xD800 + ((cp - 0x10000) >> 10), low surrogate = 0xDC00 + ((cp - 0x10000) & 0x3FF).

This is why JavaScript's `'😀'.charCodeAt(0)` returns 55357 (0xD83D) — it's returning the high surrogate, not the actual code point.

Herramientas relacionadas