Character codes — ASCII and Unicode
導入済み
21:52
数系とデータ
この写真。この曲。この動画そのもの。あなたの名前、メッセージ、すべてのデバイスのすべてのファイル——コンピュータ内部では、すべてがゼロと一でしかありません。…
英語のナレーション・英語と中国語の字幕を切り替え可能
このレッスンの内容
| English | 意味 |
|---|---|
| bits/bɪts/ | A binary digit, taking the value zero or one. |
| character/ˈkærɪktə/ | A text unit such as a letter, digit, punctuation mark or other symbol. |
| code page | A table that matches characters to numbers for a particular character set. |
| bytes | Units of eight bits used to store data in a computer. |
| Unicode/ˈjuːnɪkəʊd/ | ユニコード |
| ASCII/ˈæski/ | ASCIIコード |
| encoding/enˈkəʊdɪŋ/ | エンコーディング |
| character set/ˈkærɪktə set/ | 文字集合 |
| binary code | A sequence of zeros and ones used to represent information. |
| code point/kəʊd pɔɪnt/ | コードポイント |
| control codes | Codes that give instructions for handling text instead of representing visible characters. |
| carriage return | A control code that moves the position for writing text to the start of a line. |
| Extended ASCII | A group of character codes that use eight bits to represent characters. |
| UTF-8/ˌjuː tiː ˈef eɪt/ | UTF-8符号体系 |
| UTF-16 | A way to store Unicode characters using two or four bytes each. |
| UTF-32 | A way to store Unicode characters using four bytes each. |
| binary/ˈbaɪnəri/ | A number system using base two, with the digits zero and one. |
ギブボッシュとして届いたメール
- 1990年代まで、ワルシャワで入力されたメッセージが東京で読まれる際、意味不明な文字の塊として届くことが多かった。両方のコンピュータは文字あたり8ビットを格納していた。ただ、上位の128パターンの意味について一致していなかったのである。
- ポーランドのコードページはポーランド語の文字をそこに割り当てた。日本のそれは独自の文字をそこに割り当てた。転送中にデータが破損したわけではない。バイトは無事に到着したが、異なるテーブルに基づいて読み取られたのだ。
- 解決策は、国ごとにテーブルを持つのをやめ、あらゆる言語のあらゆる文字に、将来にわたって1つの番号を与えることだった。それがユニコードであり、あなたが送信した絵文字が同じ画像として届く理由でもある。
- このレッスンは、テキストがどうやって数になるかを示している:文字集合、ASCII、ユニコード、そしてそれらを格納するためのエンコーディングである。

文字集合は各文字に番号を与える
- A computer stores no letters, only numbers. A character set is the set of characters a computer can represent, each with its own binary code.
- 1つの文字に対応する番号をそのコードポイントと呼ぶ。
Aは65、aは97、0は数字の48である。 - コードポイントは文字の意味そのものではない。合意されたラベルに過ぎない。テキストが可読なのは、両方の機械が同じ文字集合を使用しているからだ。

文字は図像であり、バイトは数である

A character is stored as a number
Each character has a code number — 'A' is 65. Flip the bits to see that code in binary and hex, exactly how the computer holds it.
A character set such as ASCII defines:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
A character set maps each character to a number (its code point), which is what the computer actually stores.
ASCII
- ASCII(American Standard Code for Information Interchange)は7ビットを使用し、$2^7 = 128$個のコードポイントを割り当てる。基本ラテン文字、数字、記号、および carriage return などの32個の制御コードが含まれる。
- 拡張ASCIIは8ビットを使用し、256個のコードポイントを割り当てる。下位128はASCIIと同一だが、上位128は地域によって異なり、これがまさにそのメールを破損させた要因である。
- コードを暗記するよう求められることはないが、数については求められる。7ビットで128、8ビットで256などである。

How many different code points does 7-bit ASCII have?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
7 bits give $2^7 = 128$ code points.
How many different code points does extended ASCII have?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Eight bits give $2^{8} = 256$. The lower $128$ match plain 7-bit ASCII; the upper $128$ vary by region.
ユニコード
- ユニコードは普遍的な文字集合であり、現在も過去も使われているあらゆる言語のほぼすべての文字、記号、および絵文字に対し、1つのコードポイントを割り当てる。その数は149,000を超えている。
- コードポイント自体と、それをどう格納するかは別物である。エンコーディングはコードポイントをバイトに変換する。
- UTF-8 UTF-8は文字あたり1〜4バイトを使用し、ASCII互換性がある:最初の128コードポイントは1バイトで、ASCIIと同一である。UTF-16は2または4バイトを使用し、UTF-32は固定の4を使用する。

Which is true of UTF-8?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
UTF-8 is a variable-length Unicode encoding (1–4 bytes); its first 128 code points match ASCII, so plain ASCII text is valid UTF-8.
What is the relationship between Unicode and UTF-8?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The set assigns the numbers; the encoding decides how many bytes each number takes. UTF-16 and UTF-32 are other encodings of the same set.
このカードは修正されたため、翻訳が更新されるまで英語で表示されます。
Worked example: compare ASCII and Unicode
- Give one advantage and one disadvantage of using Unicode instead of ASCII. [2]
- Advantage: Unicode represents far more characters 字符, so text in any script, Chinese, Arabic, Greek, and emoji can be stored, and a single document can mix languages; files are portable because there is no per-country code page to disagree about.
- Disadvantage: some Unicode encodings use more space for English-only text: UTF-16 and UTF-32 use more bytes per ASCII character than ASCII, while UTF-8 uses the same byte.
- Both halves are needed. "It has more characters" alone is one mark of two.
A key advantage of Unicode over ASCII is that it:
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
Unicode covers nearly every writing system plus symbols and emoji — far beyond ASCII's basic English set.
For English-only text, a file encoded in UTF-16 Unicode is larger than the same text in ASCII.
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
UTF-16 uses at least 2 bytes per character, so plain English text is larger than in ASCII — the trade-off for universal coverage. (UTF-8 stores ASCII characters in the same single bytes as ASCII.)
Which are advantages of Unicode over ASCII? Select すべて that apply.
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Some Unicode encodings use more space for plain English, but UTF-8 uses the same bytes as ASCII.
worked example: テキストファイルのサイズ
- 500文字のメッセージが拡張ASCIIで格納されている。このファイルのサイズはバイト単位でいくつであるか?
- 拡張ASCIIは文字あたり8ビット、すなわち1バイトを使用するため、$500 \times 1 = 500$バイト、または$500 \times 8 = 4000$ビットである。
- 同じメッセージをUTF-32で格納する場合? 文字あたり4バイトなので、2000バイトである。
- ビットあたりの数を出し、掛け算を行い、最後に単位変換を行う。途中からビットとバイトを混在させると、失点の原因になりやすい。
A 500-character message is stored in extended ASCII. How many bytes does it need (ignore any header)?
難易度 2/5 · 140 コイン + 今日初回達成時の小ボーナス
Eight bits, one byte, per character: $500 \times 1 = 500$ bytes, or $4000$ bits. In UTF-32 the same text needs $2000$ bytes.
Reading a character in binary and hex
- Because a code point is just a number, it converts like any other.
Ais 65, which is0100 0001in binary and41in hexadecimal. - Two useful patterns: the digits
0to9run from 48, and lower case is 32 more than upper case, soa(97) isA(65) plus 32. That difference is a single bit. A= 65 と与えられ、Eを求めるような問題は、暗記した表を使うのではなく、$65 + 4 = 69$ を導き出すことを求める。

The ASCII code for A is 65. What is the ASCII code for E?
難易度 1/5 · 100 コイン + 今日初回達成時の小ボーナス
The letters are consecutive, so E is four after A. Nothing has to be memorised beyond one anchor value.
このカードは修正されたため、翻訳が更新されるまで英語で表示されます。
Marks that slip away
- ASCII is 7 bits and 128 code points; extended ASCII is 8 bits and 256. Do not write 8 bits for plain ASCII.
- Unicode is a character set 字符集; UTF-8 is an encoding of it. They are not two rival sets.
- UTF-8 is variable length, 1 to 4 bytes, not always one byte and not always four.
- Some Unicode encodings use more file space for plain English than ASCII; UTF-8 uses the same bytes for ASCII characters.
このカードは修正されたため、翻訳が更新されるまで英語で表示されます。
You've got it
- a character set gives each character a code point; text is numbers plus an agreement about how to read them
- ASCII: 7 bits, 128 code points, English only · extended ASCII 扩展ASCII码: 8 bits, 256, the top half varies by region
- Unicode: one code point for every script and emoji, stored by an encoding; UTF-8 is 1 to 4 bytes and ASCII-compatible
- Unicode gains characters, portability and mixed languages; some encodings use more file space for plain English text, while UTF-8 uses the same bytes as ASCII
何が問題でしたか?この内容はサイトの運営チームだけが確認します。