Skip to content

Main content

Encoding: Utf16 Surrogate Pair Codepoint Tool

Encode one Unicode scalar as one BMP UTF-16 unit or an ordered high/low surrogate pair, rejecting surrogate code points.

Loading tool…

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

  1. Enter codepoint. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. 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 fieldMeaning and unitsAccepted input
codepointUnicode scalar integer, excluding the surrogate interval U+D800–U+DFFF.Required. Safe integer.
Output fieldInterpretationReturned shape
resultObject containing the named calculated members below.Required. Object.
result.codeUnitsCode UnitsCalculated result member: array.
json
{
  "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

  1. Calculation and input contract: encode/utf16-surrogate-pair-codepoint — tool.io

  2. The Unicode Standard: core definitions and UTF-16 — Unicode Consortium

Similar or alternative tools