โค้ดยูนิต

Encoding & Standards

การรวมบิตขั้นต่ำที่ใช้เข้ารหัสอักขระ: 8 บิตสำหรับ UTF-8, 16 บิตสำหรับ UTF-16 และ 32 บิตสำหรับ UTF-32

A code unit is the fundamental building block of a Unicode encoding form. It's important to distinguish code units from code points — a single code point may require multiple code units depending on the encoding.

In UTF-8, a code unit is 8 bits (1 byte). The emoji 😀 requires 4 code units. In UTF-16, a code unit is 16 bits (2 bytes). The same emoji requires 2 code units (a surrogate pair). In UTF-32, it's 1 code unit (4 bytes).

Many programming language string APIs operate on code units rather than code points, which is why string length calculations can be confusing with emoji.

คำที่เกี่ยวข้อง

Surrogate Pair Surrogate Pair
หน่วยโค้ด UTF-16 สองตัว (surrogate สูง U+D800-U+DBFF ตามด้วย surrogate ต่ำ U+DC00-U+DFFF) ที่แสดงอักขระที่อยู่เหนือ U+FFFF ร่วมกัน
UTF-16 UTF-16
การเข้ารหัส Unicode แบบความกว้างผันแปร ใช้ 2 หรือ 4 ไบต์ต่ออักขระ ใช้ภายในโดย JavaScript, Java และ Windows
UTF-32 UTF-32
การเข้ารหัส Unicode แบบความกว้างคงที่ ใช้ 4 ไบต์ต่ออักขระพอดี ทำให้แมปโค้ดพอยท์ได้โดยตรงแต่ใช้พื้นที่มากกว่า
UTF-8 UTF-8
การเข้ารหัส Unicode แบบความกว้างผันแปร ใช้ 1 ถึง 4 ไบต์ต่ออักขระ เป็นมาตรฐานหลักบนเว็บ (ใช้โดยเว็บไซต์กว่า 98%)

เครื่องมือที่เกี่ยวข้อง

🔢 ค้นหา Unicode ค้นหา Unicode
ป้อนจุดรหัสเช่น U+1F600 และรับ emoji, รายละเอียดการเข้ารหัส, ไบต์ UTF-8/16 และ HTML entities