Data storage and compression
แนะนำใหม่
15:06
ทำไมคอมพิวเตอร์จึงใช้เลขสองฐาน
ภายในโปรเซสเซอร์มีสวิตช์ขนาดเล็กนับพันล้านตัว แต่ละตัวสามารถเป็นได้แค่ เปิด หรือ ปิด นั่นคือสิ่งที่คอมพิวเตอร์มีทางกายภาพจริง — ไม่มีสาม, ไม่มีเจ็ด, ไม่มี…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| Data storage | |
| sound file | |
| Compression/kəmˈpreʃn/ | Representing data using fewer bits; lossless methods preserve all original data, while lossy methods discard some information. |
| bit/bɪt/ | A binary digit, taking the value zero or one. |
| nibble/ˈnɪbl/ | A group of four bits. |
| byte/baɪt/ | A group of eight bits, commonly used as a unit of data storage. |
| kibibyte/ˈkɪbɪbaɪt/ | กิบิไบต์ |
| binary/ˈbaɪnəri/ | A number system using base two, with the digits zero and one. |
| colour depth/ˈkʌlə depθ/ | The number of bits used to represent a pixel's colour, determining how many encoded colour values are available. |
| sample rate/ˈsæmpl reɪt/ | |
| sample resolution/ˈsæmpl ˌrezəˈluːʃn/ | |
| bpp | |
| Lossless/ˈlɒsləs/ | Describing compression from which the original data can be recovered exactly. |
| run-length encoding/rʌn leŋθ enˈkəʊdɪŋ/ | การเข้ารหัสแบบความยาวของชุด |
| run/rʌn/ | |
| Lossy/ˈlɒsi/ | Describing compression that discards some original information so it cannot be perfectly recovered. |
| resolution/ˌrezəˈluːʃn/ | Here, the pixel dimensions of a bitmap image, such as its width and height in pixels. |
| program files | |
| Hz | |
| characters/ˈkærɪktəz/ | A text unit such as a letter, digit, punctuation mark or other symbol. |
การบีบอัดไฟล์ให้เล็กลง
- การจัดเก็บข้อมูลวัดด้วยหน่วยที่เพิ่มขึ้นทีละขั้นโดย 1024
- เราสามารถ คำนวณ ขนาดของไฟล์ภาพหรือเสียงได้
- Compression จะทำให้ไฟล์เล็กลง
การวัดหน่วยความจำ
- bit (0/1 หนึ่งตัว) · nibble (4 bits) · byte (8 bits).
- จากนั้นแต่ละหน่วยจะมีค่าเป็น 1024× ของหน่วยก่อนหน้า (เนื่องจาก $1024 = 2^{10}$): kibibyte (KiB) = 1024 bytes, mebibyte (MiB) = 1024 KiB, gibibyte (GiB) = 1024 MiB, tebibyte (TiB) = 1024 GiB.
- ต้องหารด้วย 1024 เสมอ (ไม่ใช่ 1000) เมื่อเปลี่ยนขึ้นเป็นหน่วยที่ใหญ่กว่า

คอมพิวเตอร์แสดงข้อมูลทั้งหมดในรูปแบบไบนารี — ลำดับยาวของ 0 และ 1.

How many bytes are in 1 kibibyte (KiB)?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
1 KiB = 1024 bytes (each storage unit steps up by 1024 = 2^10).
Match each storage/compression idea to its meaning.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
File size grows with detail; compression shrinks it, losslessly or lossily.
การคำนวณขนาดไฟล์
- ภาพ (bits) $=$ ความกว้าง × ความสูง × ความลึกสี
- เสียง (bits) $=$ อัตราการสุ่มตัวอย่าง × ความละเอียดการสุ่มตัวอย่าง × เวลาเป็นวินาที
- หารด้วย 8 เพื่อแปลงเป็น bytes, แล้วหารด้วย 1024 เพื่อแปลงเป็น KiB, หารอีกครั้งเพื่อแปลงเป็น MiB
- เช่น $1024 \times 1024$ ที่ 16 bpp $= 16\,777\,216$ bits $= 2$ MiB.
An image is 100 × 100 pixels with a colour depth of 24 bits. What is its size in bits?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
width × height × colour depth = 100 × 100 × 24 = 240 000 bits.
การบีบอัดข้อมูล
- Lossless compression ทำให้ไฟล์เล็กลงโดยที่ ไม่มีการสูญเสียถาวร — สามารถสร้างข้อมูลต้นฉบับกลับมาได้เหมือนเดิม Run-length encoding (RLE) เก็บชุดซ้ำซ้อนไว้เพียงครั้งเดียว (เช่น
WWWWWWWW→ "8 W"). - Lossy compression ทำให้ไฟล์ เล็กมาก โดย กำจัดข้อมูลออกอย่างถาวร (ลดความละเอียด/อัตราสุ่มตัวอย่าง)
- ใช้ lossless สำหรับข้อความและไฟล์โปรแกรม; lossy สำหรับภาพถ่าย เพลง และวิดีโอ

Run-length encoding เก็บชุดซ้ำซ้อนไว้เพียงครั้งเดียว ในรูปของคู่ (จำนวน, ค่า): 8 W, จากนั้น 4 R.

Run-length encoding shrinks repeats
Compression makes a file smaller. Run-length encoding replaces a run of identical values with one value plus a count — lossless, and best when the data has long runs.
Lossless compression:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Lossless keeps all the data (e.g. RLE); lossy permanently discards some.
Run-length encoding (RLE) compresses data by:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
RLE replaces a run like WWWWWWWW with "8 W" — great when data has many repeats.
Lossy compression is most appropriate for:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Lossy suits media where a slight quality loss buys a much smaller file; exact data needs lossless.
การ์ดนี้เป็นการ์ดใหม่ จึงแสดงเป็นภาษาอังกฤษจนกว่าคำแปลจะพร้อม
Worked example: a sound file, then RLE
A 10-second sound is recorded at 8000 Hz 赫兹 with a sample resolution of 16 bits. Find its size in KiB. Then compress the line WWWWWWBBBW with run-length encoding.
- Multiply, then step up the units:
- RLE stores each run as a count and a value: 6W 3B 1W. Ten characters 字符 become three pairs, and nothing is lost, so this is lossless compression.

An image is 100 pixels wide and 50 pixels high, with a colour depth of 8 bits. What is its size in bytes?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$100 \times 50 \times 8 = 40\,000$ bits, and $40\,000 \div 8 = 5000$ bytes.
Which file must be compressed with a lossless method?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
If even one bit of a program changes, it will not run correctly; photos, music and video can lose detail people do not notice.
คุณเข้าใจแล้ว
- หน่วยความจำเพิ่มขึ้นทีละ 1024 (KiB, MiB, GiB, TiB)
- ขนาดภาพ = ความกว้าง × ความสูง × ความลึกสี (bits); เสียง = อัตรา × ความละเอียด × วินาที
- lossless = ฟื้นฟูได้ครบถ้วน (RLE); lossy = เล็กกว่า แต่สูญเสียข้อมูลถาวร
- lossless สำหรับข้อความ/โปรแกรม; lossy สำหรับ ภาพถ่าย/เพลง/วิดีโอ
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้