コード単位

Encoding & Standards

文字を符号化するための最小ビット単位。UTF-8では8ビット、UTF-16では16ビット、UTF-32では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.

関連用語

UTF-16 UTF-16
1文字あたり2または4バイトを使用する可変長Unicode符号化方式。JavaScript、Java、Windowsが内部的に使用している。
UTF-32 UTF-32
1文字あたり正確に4バイトを使用する固定長Unicode符号化方式。コードポイントへの直接マッピングが可能だが、ストレージ効率が低い。
UTF-8 UTF-8
1文字あたり1〜4バイトを使用する可変長Unicode符号化方式。ウェブで最も普及しており、98%以上のウェブサイトで使用されている。
サロゲートペア サロゲートペア
U+FFFFを超える文字を表すために使用される2つのUTF-16コード単位の組み合わせ。上位サロゲート(U+D800〜U+DBFF)と下位サロゲート(U+DC00〜U+DFFF)で構成される。

関連ツール

🔢 Unicode 検索 Unicode 検索
U+1F600 のようなコードポイントを入力すると、対応する絵文字、エンコード詳細、UTF-8/16 バイト、HTML エンティティを確認できます。