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. |
האימייל שהגיע כערימות תווים
- דרך ה-1990s, הודעה שהוכנסה בווורשה ונקראה בטוקיו הגיעה לעיתים קרובות כקיר של טקסט חסר משמעות. שני המחשבים אחסנו שמונה ביטים לכל אות. הם פשוט חלקו על המשמעות של הדגמים ב-128 העליונים.
- טבלת הקידוד הפולנית השתמשה במקום הזה לאותיות פולניות. הטבלה היפנית השתמשה בה לאותיות יפניות. לא קרה שום נזק במהלך השידור: הבאייטים הגיעו שלמים ונקראו לפי טבלה שונה.
- הפתרון היה להפסיק להשתמש בטבלות נפרדות לכל מדינה ולספק כל אות בכל מערכת כתב מספר יחיד, לנצח. זו יוניקוד, ולפיכך האמוג'י שאתה שולח מגיע כאותו תמונה.
- שיעור זה מסביר איך טקסט הופך למספרים: מערכות קידוד אותיות, ASCII, יוניקוד, והקידודים שאוחסנים אותם.

מערכת קידוד אותיות מעניקה כל אות מספר
- מחשב אינו אוסף אותיות, רק מספרים. מערכת קידוד אותיות היא קבוצת האותיות שמחשב יכול לייצג, כאשר לכל אות יש קוד בינארי משלו.
- המספר המיועד לאות אחת הוא נקודת הקידוד שלה.
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 (הקוד האמריקאי הסטנדרטי להחלפת מידע) משתמש ב-7 ביטים, מה שמספק $2^7 = 128$ נקודות קוד: האותיות הלטיניות הבסיסיות, המספרים, הניקוד ו-32 פקודות בקרה כמו החזרת גלגלת.
- Extended 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.
Unicode
- Unicode הוא סט דמויות אוניברסלי: נקודת קוד אחת לכל כמעט כל דמות בכל כתב חי או מת, בנוסף לסמלים ואימוג'י, מעל 149,000 מהם.
- נקודת הקוד נפרדת מאופן האחסון שלה. Encoding (הכנה/אניקודינג) ממיר נקודת קוד לבתי-ביט.
- UTF-8: UTF-8 משתמש ב-1 עד 4 בייטים לדמות והוא תואם ASCII: ה-128 נקודות הקוד הראשונות הן בייט אחד, זהות ל-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.
קריאת דמות בבנרי ובאקסאדצימלי
- מכיוון שנקודת קוד היא פשוט מספר, היא מומרת כמו כל מספר אחר.
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
מה השתבש? רק צוות האתר רואה זאת.