コンテンツへスキップ
uencoder

テキスト エンコード リファレンス

リファレンス 用 文字 encodings: UTF-8, UTF-16, UTF-32, および 変換 間 them.

UTF Encoding Forms

UTF-8 uses 1-4 bytes per code point: ASCII (1 byte), Latin (2), CJK (3), emoji/auxiliary (4). UTF-16 uses 2 bytes for BMP and 4 (surrogate pairs) for supplementary planes. UTF-32 uses 4 bytes for every code point (simple but space-inefficient). UTF-8 is the dominant web encoding (98%+ of pages). UTF-8 is ASCII-compatible and variable-length. UTF-16 is used internally by Java, JavaScript, and Windows APIs. BOM (U+FEFF) indicates byte order but is optional and sometimes problematic.

UTF-8
1-4 bytes, ASCII compat
web standard
UTF-16
2 or 4 bytes
Java/JS internal
BOM
Byte order mark
optional

Conversion and Pitfalls

Converting between encodings requires correct handling of invalid sequences and unmappable characters. Replacement character (U+FFFD) substitutes for invalid bytes. Surrogate halves in UTF-16 are invalid alone and must be handled. JavaScript strings are UTF-16; use TextEncoder/TextDecoder for UTF-8 conversion. Length differs by encoding: str.length is UTF-16 code units, not code points or bytes. Counting code points requires iterating with for...of or [...str]. Byte length of UTF-8 requires new TextEncoder().encode(str).length.

U+FFFD
Replacement char
invalid bytes
JS strings
UTF-16 internally
code units
byte length
TextEncoder
UTF-8 bytes

関連ツール

参考链接