Surrogate Pair

Encoding & Standards

Hai đơn vị mã UTF-16 (một surrogate cao U+D800-U+DBFF theo sau là một surrogate thấp U+DC00-U+DFFF) cùng nhau đại diện cho một ký tự trên U+FFFF.

Characters with code points above U+FFFF cannot fit in a single 16-bit value. UTF-16 solves this by encoding them as two 16-bit values called a surrogate pair. Since most emoji are above U+FFFF, surrogate pairs are extremely common with emoji.

For example, 😀 (U+1F600) becomes the surrogate pair 0xD83D 0xDE00 in UTF-16. The formula: high surrogate = 0xD800 + ((cp - 0x10000) >> 10), low surrogate = 0xDC00 + ((cp - 0x10000) & 0x3FF).

This is why JavaScript's `'😀'.charCodeAt(0)` returns 55357 (0xD83D) — it's returning the high surrogate, not the actual code point.

Thuật ngữ liên quan

Code Unit Code Unit
Tổ hợp bit tối thiểu dùng để mã hóa một ký tự: 8 bit cho UTF-8, 16 bit cho UTF-16 và 32 bit cho UTF-32.
Plane Plane
Một nhóm gồm 65,536 điểm mã Unicode liên tiếp. Plane 0 là Basic Multilingual Plane (BMP); hầu hết emoji nằm ở Plane 1 (SMP).
Supplementary Multilingual Plane (SMP) Supplementary Multilingual Plane (SMP)
Unicode Plane 1 (U+10000 đến U+1FFFF), nơi phần lớn các điểm mã emoji được phân bổ.
UTF-16 UTF-16
Kiểu mã hóa Unicode có chiều rộng thay đổi, dùng 2 hoặc 4 byte cho mỗi ký tự, được JavaScript, Java và Windows dùng nội bộ.

Công cụ liên quan

🔢 Tra cứu Unicode Tra cứu Unicode
Nhập codepoint như U+1F600 để nhận emoji, chi tiết mã hóa, byte UTF-8/16 và HTML entity.
🔍 Trình phân tích chuỗi Trình phân tích chuỗi
Giải mã chuỗi ZWJ, modifier tông màu da, chuỗi phím và cặp cờ thành các thành phần riêng lẻ.