Unicode Tutorials - Herong's Tutorial Examples - Version 5.21, by Dr. Herong Yang
What Are Paired Surrogates?
This section provides a quick introduction of paired surrogates which are pairs of 16-bit integers to represent Unicode code points in the U+10000...0x10FFFF range.
The goal UTF-16 encoding is to:
The mapping for the U+0000...0xFFFF range is straightforward.
But the mapping for the U+10000...0x10FFFF range is tricky, because we want the resulting 4-byte stream can be recognized as 1 character in the U+10000...0x10FFFF range instead of 2 characters in the U+0000...0xFFFF range. This is achieved by using paired surrogates.
What Are Paired Surrogates? Paired surrogates are pairs of 2 16-bit unsigned integers in the surrogate area between 0xD800 and 0xDFFF. Since there are no Unicode characters assigned with code points in the surrogate area, Paired surrogates can be easily recognized as 1 character in the U+10000...0x10FFFF range.
The UTF-16 specification defines that the first surrogate must be in the high surrogate area between 0xD800 and 0xDBFF and the second surrogate in the low surrogate area between 0xDC00 and 0xDFFF.
Based on my understanding of the specification, here is the algorithm to convert a Unicode code point in the range of U+10000...0x10FFFF to a surrogate pair:
Exercise: Write an algorithm to convert a surrogate pair back to a Unicode code point.
Table of Contents