Description
Encode one Unicode scalar as one UTF-16 code unit or an ordered surrogate pair.
Unicode scalar values are distinct from UTF-8 bytes and UTF-16 code units. One scalar can require several units, and printable escape text is a representation of those values rather than execution or normalization of a string.
Encode one Unicode scalar as one UTF-16 code unit or an ordered surrogate pair.
When to use this tool
Use Encoding: Utf16 Surrogate Pair Codepoint when inspecting one scalar, code-unit layout or literal escape representation.
How to use the tool and how it works
- Enter codepoint. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read result. Expand result to inspect the returned fields.
Require a Unicode scalar codepoint. For a value below 65536 return that single UTF-16 code unit; otherwise subtract 65536 and split the remaining twenty bits into high and low surrogate code units using bases 55296 and 56320.1
UTF-16 distinguishes scalar values from code units and represents supplementary scalars with a surrogate pair. Literal escape text is a separate representation.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| codepoint | Unicode scalar integer, excluding the surrogate interval U+D800–U+DFFF. | Required. Safe integer. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| result | Object containing the named calculated members below. | Required. Object. |
| result.codeUnits | Code Units | Calculated result member: array. |
{
"input": {
"codepoint": 128512
},
"output": {
"result": {
"codeUnits": [
55357,
56832
]
}
}
} Limitations and assumptions
- Outputs are numeric UTF-16 code units, not endian-specific bytes. An isolated surrogate is not accepted as an input scalar, and string normalization is not performed.
- Outputs are nested inside result. Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
- Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.
Alternative or Complementary methods
Use a full Unicode encoder or parser when processing strings, and handle normalization, graphemes and context-specific escaping separately.
References
-
Calculation and input contract: encode/utf16-surrogate-pair-codepoint — tool.io
-
The Unicode Standard: core definitions and UTF-16 — Unicode Consortium
Similar or alternative tools
- Utf16 Non Bmp Escape Pair
Return a supplementary scalar’s UTF-16 surrogate values and literal paired escape spelling.
- UTF-8 BOM Octet Triplet
Return octets [239,187,191] when include is true and an empty array otherwise.