DATA REPRESENTATION CHECKS

Checking a supplementary Unicode scalar against surrogate notation

U+1F600 is one complete character, and U+D83D is half of how UTF-16 writes it. This guide separates scalar values from surrogate code units and shows why the converter accepts the first and rejects the second.

Code points, scalar values and the gap between them

The Unicode codespace runs from U+0000 to U+10FFFF, which is 1,114,112 code points. A scalar value is any code point except the 2,048 surrogate code points in the range U+D800 to U+DFFF, leaving 1,112,064 scalar values. Only scalar values are characters that can be written in a well-formed text. The surrogate range is reserved for UTF-16 machinery. The Unicode Standard defines this distinction, and it explains why the converter treats U+1F600 as a valid entry and U+D83D as invalid. The first is a scalar value, the grinning face emoji. The second is a code point that the standard sets aside and forbids as a character on its own.

How UTF-16 uses the reserved range

UTF-16 stores each character in 16-bit code units. Characters up to U+FFFF fit in one unit, but characters above that, like U+1F600, need two. The method subtracts 0x10000 from the code point, leaving a 20-bit number, then splits it into a high 10 bits and a low 10 bits. For U+1F600 the subtraction gives 0xF600. The high part is 0x3D, added to 0xD800, which yields 0xD83D. The low part is 0x200, added to 0xDC00, which yields 0xDE00. The pair D83D DE00 therefore encodes the single character. High surrogates cover D800 to DBFF and low surrogates cover DC00 to DFFF, and each is meaningful only when paired with the other kind.

Why U+D83D alone is rejected

The second case asks the decoder to turn U+D83D into a character. That value is the first half of the pair above. Alone, it identifies no character, because the pair is what carries the information. Treating it as a scalar would let a half-finished UTF-16 fragment pass as a full character, and every encoder downstream would then have to decide what bytes to write. UTF-8 cannot represent it at all under RFC 3629, which excludes surrogates. The converter reports the entry as an invalid Unicode scalar. The first case, U+1F600, decodes to the emoji, and the notation carries all of the information in one value.

Three layers of the same character

The grinning face shows three layers, and each uses a different number. At the abstract layer it is the scalar value U+1F600. In UTF-16 it is the two code units D83D and DE00. In UTF-8 it is four bytes, F0 9F 98 80. Confusing these layers is common: a string length in JavaScript counts UTF-16 code units, so this one character has length 2, while a count of scalar values gives 1 and a byte count in UTF-8 gives 4. This converter's U+ notation lives at the scalar layer. If you copy values from a debugger that shows UTF-16 units, you are looking at another layer, and pasting D83D as U+D83D mixes them.

A lone surrogate in the wild

Isolated surrogates appear when text is cut in the middle of a pair. Slicing a JavaScript string at index 1 of the emoji leaves the high unit alone. Truncating a UTF-16 buffer at a byte limit can do the same. Some systems, such as older Windows file names, allow unpaired surrogates, and the WTF-8 encoding exists to represent them, but they are not valid Unicode text. Standard libraries respond differently: some replace them with U+FFFD, the replacement character, some throw an error and some pass them through. A strict converter that rejects them makes the problem visible instead of burying it.

Writing the notation correctly

The U+ notation uses hexadecimal digits with at least four digits, so U+0041 is the letter A, U+00E9 is e with an acute accent, and U+1F600 has five digits. Letters in the hex digits are case-insensitive in practice, though the standard prints them in capitals. Values above U+10FFFF do not exist, so U+110000 is invalid for a different reason from U+D83D. When decoding, give one scalar per entry in the format the page describes. A pair of surrogate entries, such as U+D83D followed by U+DE00, is not an accepted substitute for U+1F600, even though a UTF-16 reader would combine the two code units into that character. If you only have the pair, apply the formula in reverse: subtract 0xD800 from the high unit and 0xDC00 from the low unit, shift the first result left by 10 bits, add the second, then add 0x10000. For D83D and DE00 that returns 0x1F600, and you can enter that value.

Where to find the right value

To get the scalar value of a character, look it up in the Unicode Character Database or the code charts published by the Unicode Consortium. The emoji range includes U+1F600 to U+1F64F for emoticons. Many editors can show the code point of the character at the cursor. Programming languages expose it too: Python's ord on a one-character string returns the scalar value, and JavaScript's codePointAt does the same, while charCodeAt returns the UTF-16 unit and therefore gives 55357 (0xD83D) for this emoji. If a tool reports a number in the D800 to DFFF range, you have a UTF-16 unit, and you need the second unit and the combining formula to reach the scalar.

Choosing a Unicode layer when you store text

Different systems settled on different internal layers, and knowing which one yours uses explains many surprises. Java, JavaScript, C# and Windows APIs hold strings as UTF-16 code units, so string length and indexing count units, and a character above U+FFFF occupies two positions. Python 3 strings index by code point, so the emoji has length 1. Rust strings are UTF-8 bytes, and its char type is a scalar value, which is why Rust cannot hold a lone surrogate in a char at all. Databases and files usually store UTF-8. When you pass text between these layers, convert whole scalar values, never raw units, and cut strings only at scalar boundaries so that no pair is split.

What this comparison covers

The guide tests one supplementary scalar and one isolated surrogate in the decode direction. It does not test every plane, normalization forms or grapheme clusters, where several scalars form one visible symbol, as in flag emoji built from two regional indicator letters. It also does not say which behavior other software should have for lone surrogates. The finding is limited to this converter: scalar values decode, surrogate-range entries are rejected with an invalid scalar message, and a surrogate pair written as two U+ entries is not interpreted as one character.

Reproduce the checks

Complete supplementary scalar

Open the Unicode Converter and enter:

Text or encoded input
U+1F600
Calculation mode
decode

Expected output:

Code points

😀

The input identifies one scalar value.

Isolated surrogate rejected

Open the Unicode Converter and enter:

Text or encoded input
U+D83D
Calculation mode
decode

Expected rejection:

Invalid Unicode scalar

The surrogate-range entry is not a complete scalar value.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks