UTF-16 Encoder

Enter text to see its UTF-16 code units in hexadecimal.

How it is calculated

The tool reads your text as UTF-8, finds each character's code point, and writes its UTF-16 code units as four-digit uppercase hex. A code point up to U+FFFF is one unit equal to the code point. A code point above that is split into a surrogate pair: v = cp − 0x10000, high = 0xD800 + (v ≫ 10), low = 0xDC00 + (v & 0x3FF). Units are shown in big-endian order (UTF-16BE) with no byte-order mark; UTF-16LE would swap the two bytes inside each unit. The count is the number of code units, not characters, so it is larger than the character count when pairs appear. Empty input or invalid UTF-8 gives no result.

Worked example

Encode "Hi😀". H is U+0048, giving unit 0048, and i is U+0069, giving 0069. The emoji 😀 is U+1F600, above U+FFFF, so subtract 0x10000: 0x1F600 − 0x10000 = 0xF600. The high 10 bits are 0xF600 ≫ 10 = 0x3D, so high = 0xD800 + 0x3D = D83D. The low 10 bits are 0xF600 & 0x3FF = 0x200, so low = 0xDC00 + 0x200 = DE00. The tool returns 0048 0069 D83D DE00, which is 4 code units for 3 characters.

Try this example →

Common mistakes

  • Counting characters from the unit count. An emoji or other supplementary character takes two units, so "Hi😀" has 3 characters but 4 code units, as in JavaScript where its length is 4.
  • Reading the output as UTF-8 bytes. 20AC for € is a UTF-16 unit; the UTF-8 form is the three bytes E2 82 AC.
  • Expecting a byte-order mark or little-endian order. The units are shown big-endian without FEFF, so for a UTF-16LE file swap the bytes of each unit (0048 becomes 48 00).
  • Treating D83D or DE00 on its own as a character. A surrogate unit is only meaningful together with its partner and cannot stand alone.
  • Pasting text with invisible characters, such as spaces, line breaks or zero-width joiners, and not expecting them. They are encoded too (a space is 0020).

Sources

About this calculator

UTF-16 encodes Unicode text as a sequence of 16-bit code units. Any character in the Basic Multilingual Plane (BMP, code points U+0000 through U+FFFF — which covers Latin, Cyrillic, Greek, most CJK ideographs, and far more) is represented directly as a single 16-bit code unit equal to its code point. Characters outside the BMP — code points from U+10000 up through U+10FFFF, which include emoji, many historic and less-common scripts, and supplementary CJK ideographs — can’t fit in 16 bits, so UTF-16 represents them with a surrogate pair: two 16-bit units drawn from reserved ranges that only ever appear together.

The surrogate pair is formed by subtracting 0x10000 from the code point to get a 20-bit value, then splitting it into a high 10 bits added to 0xD800 (giving a “high surrogate” in the range 0xD800–0xDBFF) and a low 10 bits added to 0xDC00 (a “low surrogate” in the range 0xDC00–0xDFFF). This matters directly to developers because JavaScript strings, Java chars, and the Windows API all use UTF-16 internally, which is why a single emoji can report a .length of 2 in JavaScript. This calculator encodes input text into its UTF-16 code units, showing each in hexadecimal and using surrogate pairs wherever needed.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    The code units shown double as escape sequences. For the default Hi plus the grinning-face character, the pair D83D DE00 is written as \uD83D\uDE00 in a JavaScript, Java or JSON string. Because the tool counts units, the 4 it reports matches what a JavaScript string length gives for that text. Do you also need UTF-16LE output or a 0x prefix on each unit?

Popular calculators

All Calculators