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/ | |
| 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-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 ลวดลายบนสุด
- ตารางรหัสประเทศโปแลนด์วางตัวอักษรโปแลนด์ไว้ที่นั่น. ญี่ปุ่นวางอักขระของตัวเองไว้ที่นั่น. ไม่มีอะไรเสียหายระหว่างการส่ง: ไบต์มาถึงอย่างสมบูรณ์และอ่านตามตารางอื่น.
- วิธีแก้ไขคือการหยุดการใช้ตารางแยกตามประเทศและมอบ รหัส ให้กับ ทุก ตัวอักษรใน ทุก ระบบเขียน เพื่อถาวร นั่นคือ Unicode และนั่นคือเหตุผลว่าทำไม emoji ที่คุณส่งถึงจะปรากฏเป็นภาพเดิม
- บทเรียนนี้คือวิธีที่ข้อความกลายเป็นตัวเลข: ชุดตัวอักษร (character sets), ASCII, Unicode และการเข้ารหัสที่ใช้เก็บข้อมูลเหล่านั้น

ชุดตัวอักษรให้รหัสกับแต่ละตัวอักษร
- คอมพิวเตอร์ไม่เก็บตัวอักษร มีเพียงตัวเลข ชุดตัวอักษร คือชุดของตัวอักษรที่คอมพิวเตอร์สามารถแทนค่าได้ โดยแต่ละตัวมีรหัสไบนารีของตัวเอง
- ตัวเลขแทนหนึ่งตัวอักษรเรียกว่า code point.
Aคือ 65,aคือ 97, และเลข0คือ 48. - Code point ไม่ใช่ความหมายของตัวอักษร แต่เป็นฉลากที่ตกลงกันไว้ ข้อความอ่านได้ก็เพราะเครื่องทั้งสองใช้ชุดตัวอักษรเดียวกัน

ตัวอักษรคือภาพ; ไบต์คือตัวเลข

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$ code points: ตัวอักษรลาตินพื้นฐาน เลข symbol และ 32 control codes เช่น carriage return
- Extended ASCII ใช้ 8 บิต ทำให้ได้ 256 code points 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.
Unicode
- Unicode เป็นชุดตัวอักษรสากล: code point เดียวสำหรับเกือบทุกตัวอักษรในทุกภาษาที่ยังมีชีวิตอยู่หรือสิ้นสูญ รวมถึงสัญลักษณ์และ emoji มากกว่า 149,000 ตัว
- จุดโค้ดแยกจากการจัดเก็บ การ เข้ารหัสแปลงจุดโค้ดให้เป็นบิต
- UTF-8 UTF-8 ใช้ 1 เพื่อ 4 ไบต์ต่อตัวอักษร และเป็น ASCII-compatible: 128 code point แรกมีขนาด 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.
ตัวอย่างวิธีทำ: ขนาดไฟล์ข้อความ
- ข้อความ 500 ตัวอักษรถูกจัดเก็บใน Extended ASCII ไฟล์มีขนาดใหญ่กี่ไบต์?
- Extended ASCII ใช้ 8 บิต, หนึ่งไบต์ ต่อตัวอักษร ดังนั้นจึงได้ $500 \times 1 = 500$ ไบต์, หรือ $500 \times 8 = 4000$ บิต
- ข้อความเดียวกันใน UTF-32? สี่ไบต์ต่อตัวอักษร ดังนั้นได้ 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.
อ่านตัวอักษรในรูปแบบไบนารีและเฮกซ์
- เนื่องจาก code point เป็นเพียงตัวเลข มันจึงแปลงได้เหมือนตัวเลขอื่นๆ
Aคือ 65 ซึ่งเป็น0100 0001ในรูปแบบไบนารีและ41ในรูปแบบเฮกซ์ - ลวดลายที่มีประโยชน์สองอย่าง: เลข
0ถึง9เริ่มตั้งแต่ 48 และตัวพิมพ์เล็กมีค่ามากกว่าตัวพิมพ์ใหญ่ 32 ดังนั้นa(97) คือA(65) บวก 32 ความต่างนี้เป็นบิตเดียว - คำถามที่ให้
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
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้