L
LLLOS.ai
Learn
L

Ask Your Tutor · Computer Science

How do you convert a character above U+FFFF into a surrogate pair?

General knowledge Asked by Anonymous from New York, United States 24 Oct 2026, 7:41 AM IST Updated

In one line

To convert a character above U+FFFF into a surrogate pair, you break its code point into two special 16-bit numbers used in UTF-16.

The rule

Characters above U+FFFF (code points from U+10000 to U+10FFFF) are stored in UTF-16 using two 16-bit values called a surrogate pair.

The formula:

  • Subtract 0x10000 from the code point to get a 20-bit number.
  • The top 10 bits become the high surrogate: 0xD800 + (top 10 bits)
  • The bottom 10 bits become the low surrogate: 0xDC00 + (bottom 10 bits)
The formula
High = 0xD800 + (code − 0x10000) >> 10 Low = 0xDC00 + (code − 0x10000) & 0x3FF
codethe Unicode code point
Highhigh surrogate
Lowlow surrogate

Let's understand it simply

Imagine you want to write a big number, but your notebook only has space for 4 digits on each page. If your number is too big, you split it across two pages. Similarly, in computers, the normal way (UTF-16) can only store up to U+FFFF in one piece. For bigger numbers (above U+FFFF), we break them into two parts, called a surrogate pair. Each part fits into the 16-bit space.

How it works

  1. Write the character's code point (for example, U+1F600 for 😀).
  2. Subtract 0x10000 (65536 in decimal) from it. This gives you a 20-bit number.
  3. Take the top 10 bits of this number. Add 0xD800 (55296) to get the high surrogate.
  4. Take the bottom 10 bits. Add 0xDC00 (56320) to get the low surrogate.
  5. Write both surrogates in order. Together, they represent your character in UTF-16.
Converting a code point above U+FFFF to a surrogate pair
  1. Write the code point (e.g., U+1F600)
  2. Subtract 0x10000
  3. Split into top 10 and bottom 10 bits
  4. Add 0xD800 to top 10 bits for high surrogate
  5. Add 0xDC00 to bottom 10 bits for low surrogate
  6. Write both surrogates in order

The story behind it

When Unicode was first made, it was thought 16 bits (U+0000 to U+FFFF) would be enough. But later, more characters were needed (like emojis, rare scripts). UTF-16 was updated to use surrogate pairs, so computers could handle all these new symbols without breaking old software.

Where you see it in real life

  • 600 (😀) emoji: Needs a surrogate pair in UTF-16 to be stored or shown.
  • Ancient scripts: Some rare Indian scripts (like Brahmi) use code points above U+FFFF.
  • Musical symbols: Special notes and marks in sheet music apps.
  • Some maths symbols: Used in scientific calculators or maths software.
  • Programming: When you type or process emojis in Python, Java, or JavaScript, they use surrogate pairs inside.

Why it matters

  • Lets computers store and show all world scripts, emojis, and symbols.
  • Needed for modern apps, websites, and phones that use emojis or rare scripts.
  • Important for programmers working with text, especially in Indian languages.
  • Questions on Unicode and encoding come in computer science exams.

Worked example

Let's convert U+1F600 (😀) into a surrogate pair:

Given: Code point = U+1F600
Step 1: Subtract 0x10000      0x1F600 - 0x10000 = 0xF600
Step 2: Top 10 bits           0xF600 >> 10 = 0x3D (61 in decimal)
Step 3: High surrogate        0xD800 + 0x3D = 0xD83D
Step 4: Bottom 10 bits        0xF600 & 0x3FF = 0x600
Step 5: Low surrogate         0xDC00 + 0x600 = 0xDE00
Step 6: Answer                Surrogate pair is 0xD83D 0xDE00

Common mistakes

  • Forgetting to subtract 0x10000 first. Always do this before splitting bits.
  • Mixing up high and low surrogates. High surrogate always starts with 0xD8, low with 0xDC.
  • Trying to use surrogate pairs for code points below U+10000. Only needed for bigger ones.

Remember it

Big Unicode needs two pages in UTF-16: high (D8xx) and low (DCxx) surrogates.

Check yourself

Why do we need surrogate pairs in UTF-16?

Because one 16-bit value is not enough for code points above U+FFFF.

What do you subtract from the code point before making a surrogate pair?

Subtract 0x10000 (65536 in decimal).

If a code point is U+1F600, what is the high surrogate?

0xD83D.

Can you use surrogate pairs for U+0905 (अ)? Why or why not?

No, because U+0905 is below U+10000 and fits in one 16-bit value.

Quick recap

  • Characters above U+FFFF need two 16-bit values in UTF-16.
  • Subtract 0x10000, split into top and bottom 10 bits.
  • High surrogate starts with 0xD8, low with 0xDC.
  • Surrogate pairs let computers handle emojis and rare scripts.
Written by the LLOS.ai tutor. Asked by Anonymous from New York, United States on 24 Oct 2026, 7:41 AM IST