Copied!
Free Tool • Auto Encode • No Registration

UTF16 Encode String

Online Free Developer Tool — Instant UTF-16 Encoder, Unicode Code Unit Converter

| Byte Order: | | Output Format: | Sep:
0 chars
:
0 units

Chars

0

Code Units

0

Bytes

0

Surrogates

0

BOM

No

Byte Order

LE

Why Use Our UTF-16 Encoder Tool?

Instant Encode

Real-time auto encoding

LE & BE

Little & Big Endian support

Visualize

Code unit visualization

8 Formats

Hex, decimal, binary & more

100% Private

Client-side, no server

100% Free

Unlimited, no login

How to Encode Strings to UTF-16

1

Enter Text

Type or paste any Unicode text.

2

Auto Encode

UTF-16 code units appear instantly.

3

Configure

Set byte order, BOM, format.

4

Export

Copy, download TXT/JSON/Binary.

The Complete Guide to UTF-16 Encoding: Understanding UTF-16 String Encoding for Unicode Text Processing

In the world of text encoding and internationalization, UTF-16 holds a position of critical importance as one of the three official Unicode encoding forms, alongside UTF-8 and UTF-32. The ability to utf16 encode string data correctly is fundamental for developers building cross-platform applications, working with Windows system APIs, processing XML and JSON documents with international content, developing Java or JavaScript applications at the byte level, and working with legacy systems that use UTF-16 as their native encoding. Our free online utf16 encoder provides a comprehensive, professional-grade encoding experience entirely within your browser, with real-time auto-encoding, multiple output formats, byte order configuration, BOM support, and advanced visualization of code units.

UTF-16 is a variable-width character encoding that represents each Unicode code point using either one or two 16-bit code units (each code unit being 2 bytes). Characters in the Basic Multilingual Plane (BMP) — covering code points U+0000 through U+FFFF — are represented by exactly one 16-bit code unit. Characters outside the BMP, called supplementary characters (code points U+10000 through U+10FFFF), require two 16-bit code units called a surrogate pair. This is what makes UTF-16 variable-width: most common characters in Western, East Asian, and Middle Eastern scripts fit in a single code unit, while emoji, historical scripts, and specialized symbols often require surrogate pairs. Our free utf16 encode tool handles both cases correctly and identifies surrogate pairs in the visualization view.

The online utf16 encode process begins with decomposing the input text into Unicode code points. For BMP characters, the code point value directly becomes the 16-bit code unit value. For supplementary characters, the encoding algorithm first subtracts 0x10000 from the code point to get a 20-bit value, then splits this into a high surrogate (0xD800 through 0xDBFF) and a low surrogate (0xDC00 through 0xDFFF) using a specific bit manipulation formula. Our utf16 converter implements this algorithm precisely using JavaScript's native string processing, which itself uses UTF-16 internally, ensuring perfect accuracy.

Big-Endian vs Little-Endian: Understanding Byte Order in UTF-16

One of the most important configuration choices when you text to utf16 encode is the byte order. Since each UTF-16 code unit is 16 bits (2 bytes), there are two ways to store those bytes: big-endian (BE) order places the most significant byte first, while little-endian (LE) order places the least significant byte first. For example, the character 'A' has code point U+0041. In UTF-16 BE, this is stored as the bytes 0x00 0x41. In UTF-16 LE, it is stored as 0x41 0x00. This difference might seem subtle, but it critically affects any system that reads the raw bytes without knowing the byte order.

UTF-16 LE is the byte order used by Microsoft Windows systems, .NET applications, and many Windows-based file formats. When you open a UTF-16 text file in Windows Notepad, it uses UTF-16 LE by default. UTF-16 BE is commonly used in network protocols, legacy mainframe systems, and some UNIX variants. Our utf16 text encoder supports both byte orders with a simple toggle, and also supports the Byte Order Mark (BOM) character (U+FEFF) which can be prepended to the encoded output to indicate the byte order to decoders that encounter the data without additional context.

The BOM in UTF-16 is a pair of bytes: 0xFF 0xFE for UTF-16 LE, or 0xFE 0xFF for UTF-16 BE. When a decoder encounters these bytes at the beginning of a UTF-16 stream, it can automatically determine the byte order without relying on external metadata. Some applications always require a BOM (notably many Windows applications), while others prefer BOM-less encoding. Our utf16 encode tool makes the BOM optional, so you can match whatever your target system expects.

Eight Output Formats for Every Developer Workflow

As a comprehensive instant utf16 encode solution, our tool supports eight distinct output formats that cover every common use case for UTF-16 encoded data. The "Hex (0xXXXX)" format outputs each 16-bit code unit as a prefixed hexadecimal value like 0x0048, which is the most common format for documentation, debugging, and human-readable representation of Unicode code points. "Hex Plain" removes the prefix for more compact output suitable for parsing by programs. The "Decimal" format outputs code unit values as decimal integers, useful when working with low-level byte array APIs.

The "Binary" format shows each code unit as a 16-bit binary string, which is invaluable for understanding the bit-level structure of UTF-16 encoding and for educational purposes explaining how surrogate pairs work. The "Escaped" format produces JavaScript/Java/C#-style \uXXXX escape sequences, which are directly usable in source code for embedding Unicode strings as string literals. The "JSON Array" format produces a JSON-formatted array of integer code unit values, ready for use in JavaScript or any language with JSON parsing. The "C Array" format produces a C/C++-style array declaration suitable for embedding in C source files. Finally, the "Raw Bytes Hex" format outputs the actual bytes as they would be stored in memory, respecting the selected byte order.

This extensive format support transforms our browser utf16 encoder from a simple converter into a complete development tool that produces output ready for immediate use in any programming language or platform.

The Code Unit Visualizer: Understanding Your Text at the Unicode Level

One of the most powerful and educational features of our secure utf16 encoder is the interactive Code Unit Visualizer. When enabled, the visualizer displays each UTF-16 code unit as a colored badge showing the character, its code unit value, and whether it is a BMP character or part of a surrogate pair. BMP characters appear in indigo/purple badges, while surrogate pairs are shown in yellow/amber to make them immediately recognizable.

The Inspect mode takes this analysis even further, providing a character-by-character breakdown of the input text. For each character, the Inspect panel shows the character itself, its Unicode code point in U+XXXX notation, whether it requires a surrogate pair, the high and low surrogate values if applicable, the character name, and the script it belongs to. This level of detail makes our tool essential for developers learning about Unicode internals, debugging encoding issues, and verifying that their applications handle supplementary characters correctly.

Surrogate pair handling is one of the most common sources of Unicode bugs in applications. A character like the emoji 😀 (U+1F600) requires a surrogate pair in UTF-16: high surrogate 0xD83D and low surrogate 0xDE00. Applications that iterate over UTF-16 strings by code unit without accounting for surrogate pairs can produce incorrect results when encountering emoji, mathematical symbols, historic scripts, or any supplementary character. Our tool's surrogate visualization helps developers identify which characters in their strings require surrogate pairs and what those pairs look like in hexadecimal.

Advanced Features: Batch Processing, File Upload, and Comparison

As a professional-grade utf16 online converter, our tool includes comprehensive batch processing capabilities. The Batch mode accepts multiple strings, one per line, and encodes them all simultaneously with the current settings. Results are displayed inline with individual copy buttons, and the entire batch can be downloaded as a CSV file. This is invaluable when encoding multiple string constants for internationalization files, processing lookup tables, or generating test fixtures for UTF-16 handling code.

The File mode provides drag-and-drop upload for text files, encoding their content to UTF-16 automatically. The encoded output can be copied or downloaded directly. More importantly, the tool can also download the encoded content as a true UTF-16 binary file — a feature that goes beyond text representation to produce actual UTF-16 encoded binary data that other applications can directly read. This makes our tool valuable for generating test files for UTF-16-aware applications, creating fixtures for parser testing, and converting text content to UTF-16 format.

The Compare mode provides a side-by-side comparison of UTF-8 and UTF-16 encodings for the same input text. This comparison shows the byte count for each encoding, the code unit count, and the byte overhead ratio. For ASCII-only text, UTF-8 uses one byte per character while UTF-16 uses two — making UTF-16 twice as large for ASCII content. For East Asian characters like Japanese Kanji or Korean Hangul, both encodings typically use the same number of bytes (3 bytes for UTF-8 vs 2 bytes for UTF-16), making UTF-16 more efficient for those scripts. The comparison mode makes these tradeoffs immediately visible.

Use Cases: Where UTF-16 Encoding Matters

The encode string to utf16 functionality in our tool serves dozens of real-world development scenarios. Windows development is perhaps the most common: the Windows API uses UTF-16 LE for virtually all string handling, from file names to window titles to registry values. Developers using Win32 API functions, COM interfaces, or WMI queries deal with UTF-16 strings constantly, and our utf16 utility tool helps them understand and construct the binary representations these APIs expect.

Java development is another major use case. Java's char type is a 16-bit UTF-16 code unit, and Java strings are stored as sequences of these code units. When Java developers need to understand how their strings are represented at the byte level, or when writing custom serialization code, our best utf16 encoder provides immediate, accurate encoding that matches Java's internal representation.

JavaScript engines also use UTF-16 internally for string storage, following the ECMAScript specification. When working with String.prototype.charCodeAt(), String.fromCharCode(), or the charCodeAt and codePointAt methods, developers are working with UTF-16 code units. Our developer utf16 tool helps JavaScript developers understand the relationship between characters, code points, and the UTF-16 code units that JavaScript string methods operate on.

XML and XHTML documents can use UTF-16 encoding, and XML parsers must handle UTF-16 with or without BOM correctly. Database systems like Microsoft SQL Server and Oracle use UTF-16 for their NCHAR and NVARCHAR data types, making understanding UTF-16 encoding essential for database application developers. Our unicode utf16 encoder helps developers working with these technologies understand exactly how their string data is represented at the byte level.

Technical Accuracy: Surrogate Pairs and the Supplementary Plane

The encoding algorithm in our utf16 text converter handles supplementary characters correctly using the standard surrogate pair algorithm. For a code point C where C ≥ 0x10000, the high surrogate H is calculated as: H = 0xD800 + ((C - 0x10000) >> 10), and the low surrogate L is: L = 0xDC00 + ((C - 0x10000) & 0x3FF). Our implementation uses JavaScript's built-in string code point iteration via the spread operator and String.prototype.codePointAt() to correctly extract each Unicode code point from the input, then applies the surrogate encoding formula where necessary.

For decoding in the reverse direction, our tool reads pairs of code units and checks whether each code unit falls in the high surrogate range (0xD800 to 0xDBFF). If so, it reads the next code unit as the low surrogate (0xDC00 to 0xDFFF) and reconstructs the original code point as: C = 0x10000 + ((H - 0xD800) << 10) + (L - 0xDC00). This mathematically precise implementation ensures that every free online utf16 tool operation produces results that are byte-for-byte identical to what a conformant UTF-16 encoder would produce.

All processing in our utf16 encode text tool runs 100% client-side in your browser. No text is ever transmitted to any server, making it completely safe for encoding sensitive content such as passwords, private keys, personal data, or proprietary text. The tool works offline after the initial page load and stores history only in local browser storage, clearable at any time. Whether you are a seasoned developer needing a quick encoding reference or a student learning about Unicode internals for the first time, our fast utf16 encoder delivers professional-grade results with complete privacy and no cost whatsoever.

Frequently Asked Questions

UTF-16 represents Unicode characters using 16-bit code units (2 bytes each). Characters in the Basic Multilingual Plane use one code unit, while supplementary characters use surrogate pairs (two code units). UTF-8 uses 1-4 bytes per character and is the most common encoding for web. UTF-16 is native to Windows, Java, and JavaScript internally.

UTF-16 LE (Little-Endian) stores the least significant byte first. For 'A' (U+0041): bytes are 0x41 0x00. UTF-16 BE (Big-Endian) stores the most significant byte first: 0x00 0x41. Windows and .NET use LE. Network protocols and some systems use BE. Use BOM (Byte Order Mark) so receivers can detect the byte order automatically.

BOM (Byte Order Mark) is the Unicode character U+FEFF placed at the start of a UTF-16 stream. For UTF-16 LE it appears as bytes 0xFF 0xFE, for UTF-16 BE as 0xFE 0xFF. Decoders use these bytes to auto-detect byte order. Enable "Add BOM" in our tool to include it in the output.

Surrogate pairs represent characters outside the Basic Multilingual Plane (U+10000 to U+10FFFF), such as emoji and rare scripts. A high surrogate (0xD800-0xDBFF) followed by a low surrogate (0xDC00-0xDFFF) together encode one supplementary character. For example, 😀 (U+1F600) encodes as the pair 0xD83D 0xDE00.

Eight formats: Hex (0xXXXX) for documentation, Hex Plain for parsing, Decimal for integer values, Binary for bit-level analysis, Escaped (\uXXXX) for source code, JSON Array for JavaScript, C Array for C/C++, and Raw Bytes Hex for binary inspection. Select the format that matches your use case.

Yes! Click the "Binary" download button to download a real UTF-16 encoded binary file. The byte order and BOM settings are respected. This produces an actual binary file that UTF-16-aware applications can directly read — useful for testing parsers and generating test fixtures.

Most emoji have code points above U+FFFF, placing them in Unicode's supplementary planes. UTF-16 can only represent characters up to U+FFFF with a single 16-bit unit. For higher code points, two 16-bit units (a surrogate pair) are required, totaling 4 bytes. This is why string.length in JavaScript can return 2 for a single emoji character.

Yes! Switch to Decode mode to convert UTF-16 code units back to text. The decoder accepts hex values (0xXXXX format or plain XXXX), respects the byte order and BOM settings, and correctly handles surrogate pairs to reconstruct the original Unicode string.

100% private. All encoding runs entirely in your browser using JavaScript. No data is sent to any server. Works offline after initial page load. History stored only in local browser storage and can be cleared at any time. Safe for sensitive text including passwords and private content.

Yes, 100% free with no registration, no account, and no limits. All modes (encode, decode, batch, file, inspect, compare), all 8 output formats, byte order options, BOM, visualizer, binary download, and history are fully available to everyone at no cost.