ASCII Table ตาราง ASCII
Characters encoded as numeric codes 0–127 ตัวอักษรที่เข้ารหัสเป็นรหัสตัวเลข 0–127
Text is stored as character codes. Classic ASCII uses
7 bits, so codes run from 0 to 127 (128 characters).
Codes 0–31 are mostly control characters; printable symbols start at 32 (space).
ข้อความถูกเก็บเป็นรหัสตัวอักษร มาตรฐานASCII ใช้
7 บิต จึงมีรหัส 0 ถึง 127 (128 ตัว)
รหัส 0–31 ส่วนใหญ่เป็นตัวอักษรควบคุม; อักขระที่พิมพ์ได้เริ่มที่ 32 (ช่องว่าง)
Useful ASCII facts ข้อควรจำของ ASCII
-
ord(ch): character → denary code (e.g.ord("A")is 65).ord(ch): ตัวอักษร → รหัสฐานสิบ (เช่นord("A")ได้ 65) -
chr(n): denary code → character (e.g.chr(32)is space).chr(n): รหัสฐานสิบ → ตัวอักษร (เช่นchr(32)คือช่องว่าง) -
Same code, many bases: show denary,
bin(), andhex()for one value. รหัสเดียวกันหลายฐาน: แสดงฐานสิบ,bin()และhex()ของค่าเดียวกัน
How ASCII is used การใช้งาน ASCII
Because every machine agrees on the same code for each character, a program can compare and sort text by its codes, store or send text as bytes, and work out one character from another by arithmetic on the code. A few everyday uses:
เพราะทุกเครื่องใช้รหัสเดียวกันสำหรับแต่ละตัวอักษร โปรแกรมจึงเทียบและเรียงข้อความจากรหัสได้ เก็บหรือส่งข้อความเป็นไบต์ได้ และคำนวณหาตัวอักษรหนึ่งจากอีกตัวได้ด้วยการบวกลบรหัส ตัวอย่างการใช้งานที่พบบ่อย:
| Useการใช้งาน | Exampleตัวอย่าง |
|---|---|
| Store / send text as bytesเก็บ / ส่งข้อความเป็นไบต์ | A text file or a serial link sends "Hi" as codes 72, 105.ไฟล์ข้อความหรือพอร์ต serial ส่ง "Hi" เป็นรหัส 72, 105 |
| Sort / compare wordsเรียง / เทียบคำ | "Apple" < "banana" is True because ord("A") 65 < ord("b") 98."Apple" < "banana" เป็น True เพราะ ord("A") 65 < ord("b") 98 |
| Check a character rangeตรวจช่วงของอักขระ | A character is a digit when its code is 48–57.อักขระเป็นตัวเลขเมื่อรหัสอยู่ในช่วง 48–57 |
| Convert letter caseเปลี่ยนพิมพ์เล็ก / พิมพ์ใหญ่ | Lower and upper of the same letter differ by 32 (ord("a") - ord("A")).พิมพ์เล็กกับพิมพ์ใหญ่ของตัวอักษรเดียวกันต่างกัน 32 (ord("a") - ord("A")) |
1 Convert letter case with the 32 gap 1 เปลี่ยนพิมพ์เล็ก↔พิมพ์ใหญ่ด้วยผลต่าง 32
For every letter, ord("a") - ord("A") is 32. So chr(ord("a") - 32)
gives the uppercase letter, and chr(ord("A") + 32) gives the lowercase one.
สำหรับทุกตัวอักษร ord("a") - ord("A") เท่ากับ 32 เสมอ
ดังนั้น chr(ord("a") - 32) ได้ตัวพิมพ์ใหญ่ และ chr(ord("A") + 32) ได้ตัวพิมพ์เล็ก
32 A a
2 Tell a character type from its code range 2 ตรวจชนิดอักขระด้วยช่วงรหัส
Digits are codes 48–57, uppercase letters 65–90,
lowercase letters 97–122. for ch in "A7?" visits each
character; if / elif / else picks the matching range.
ตัวเลขคือรหัส 48–57, ตัวพิมพ์ใหญ่ 65–90,
ตัวพิมพ์เล็ก 97–122 คำสั่ง for ch in "A7?" วนอ่านอักขระทีละตัว
แล้ว if / elif / else เลือกช่วงที่ตรง
A upper 7 digit ? other
ASCII table (codes 0–127) ตาราง ASCII (รหัส 0–127)
Codes 0–31 and 127 are control characters, shown here by their
abbreviation (NUL, LF, CR, ESC, DEL, …);
32 is space (SP). Codes 32–126 are printable.
รหัส 0–31 และ 127 เป็นตัวอักษรควบคุม แสดงด้วยตัวย่อ
(NUL, LF, CR, ESC, DEL …)
รหัส 32 คือช่องว่าง (SP) ส่วนรหัส 32–126 พิมพ์ได้
| Dec | Hex | Chr | Dec | Hex | Chr | Dec | Hex | Chr | Dec | Hex | Chr |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 00 | NUL | 32 | 20 | SP | 64 | 40 | @ | 96 | 60 | ` |
| 1 | 01 | SOH | 33 | 21 | ! | 65 | 41 | A | 97 | 61 | a |
| 2 | 02 | STX | 34 | 22 | " | 66 | 42 | B | 98 | 62 | b |
| 3 | 03 | ETX | 35 | 23 | # | 67 | 43 | C | 99 | 63 | c |
| 4 | 04 | EOT | 36 | 24 | $ | 68 | 44 | D | 100 | 64 | d |
| 5 | 05 | ENQ | 37 | 25 | % | 69 | 45 | E | 101 | 65 | e |
| 6 | 06 | ACK | 38 | 26 | & | 70 | 46 | F | 102 | 66 | f |
| 7 | 07 | BEL | 39 | 27 | ' | 71 | 47 | G | 103 | 67 | g |
| 8 | 08 | BS | 40 | 28 | ( | 72 | 48 | H | 104 | 68 | h |
| 9 | 09 | HT | 41 | 29 | ) | 73 | 49 | I | 105 | 69 | i |
| 10 | 0A | LF | 42 | 2A | * | 74 | 4A | J | 106 | 6A | j |
| 11 | 0B | VT | 43 | 2B | + | 75 | 4B | K | 107 | 6B | k |
| 12 | 0C | FF | 44 | 2C | , | 76 | 4C | L | 108 | 6C | l |
| 13 | 0D | CR | 45 | 2D | - | 77 | 4D | M | 109 | 6D | m |
| 14 | 0E | SO | 46 | 2E | . | 78 | 4E | N | 110 | 6E | n |
| 15 | 0F | SI | 47 | 2F | / | 79 | 4F | O | 111 | 6F | o |
| 16 | 10 | DLE | 48 | 30 | 0 | 80 | 50 | P | 112 | 70 | p |
| 17 | 11 | DC1 | 49 | 31 | 1 | 81 | 51 | Q | 113 | 71 | q |
| 18 | 12 | DC2 | 50 | 32 | 2 | 82 | 52 | R | 114 | 72 | r |
| 19 | 13 | DC3 | 51 | 33 | 3 | 83 | 53 | S | 115 | 73 | s |
| 20 | 14 | DC4 | 52 | 34 | 4 | 84 | 54 | T | 116 | 74 | t |
| 21 | 15 | NAK | 53 | 35 | 5 | 85 | 55 | U | 117 | 75 | u |
| 22 | 16 | SYN | 54 | 36 | 6 | 86 | 56 | V | 118 | 76 | v |
| 23 | 17 | ETB | 55 | 37 | 7 | 87 | 57 | W | 119 | 77 | w |
| 24 | 18 | CAN | 56 | 38 | 8 | 88 | 58 | X | 120 | 78 | x |
| 25 | 19 | EM | 57 | 39 | 9 | 89 | 59 | Y | 121 | 79 | y |
| 26 | 1A | SUB | 58 | 3A | : | 90 | 5A | Z | 122 | 7A | z |
| 27 | 1B | ESC | 59 | 3B | ; | 91 | 5B | [ | 123 | 7B | { |
| 28 | 1C | FS | 60 | 3C | < | 92 | 5C | \ | 124 | 7C | | |
| 29 | 1D | GS | 61 | 3D | = | 93 | 5D | ] | 125 | 7D | } |
| 30 | 1E | RS | 62 | 3E | > | 94 | 5E | ^ | 126 | 7E | ~ |
| 31 | 1F | US | 63 | 3F | ? | 95 | 5F | _ | 127 | 7F | DEL |
Control characters (codes 0–32, and 127) อักขระควบคุม (รหัส 0–32 และ 127)
Control codes do not print a shape — they tell a device to do something. The two form columns write the same code two ways (explained under the table):
รหัสควบคุมไม่ได้พิมพ์รูปอักขระ แต่เป็นคำสั่งให้อุปกรณ์ทำงานบางอย่าง คอลัมน์ รูปแบบ สองช่องเขียนรหัสเดียวกันสองวิธี (อธิบายไว้ใต้ตาราง):
| Abbr.ตัวย่อ | Nameชื่อเต็ม | Dec | Form Aแบบ A | Form Bแบบ B | Meaningความหมาย |
|---|---|---|---|---|---|
NUL |
Nullนัล | 0 | ^@ |
\0 |
End-of-string marker in C; "no character".ตัวปิดท้ายสตริงในภาษา C; "ไม่มีอักขระ" |
SOH |
Start of Headingเริ่มส่วนหัว | 1 | ^A |
— | Marks the start of a message header (old comms protocols).เริ่มต้นส่วนหัวของข้อความ (โปรโตคอลสื่อสารรุ่นเก่า) |
STX |
Start of Textเริ่มเนื้อความ | 2 | ^B |
— | Marks where the message body begins.จุดเริ่มต้นของเนื้อความ |
ETX |
End of Textจบเนื้อความ | 3 | ^C |
— | Marks the end of the message body. Ctrl+C sends this.จุดสิ้นสุดเนื้อความ; Ctrl+C ส่งรหัสนี้ |
EOT |
End of Transmissionจบการส่ง | 4 | ^D |
— | No more data. Ctrl+D sends this (end of input).ไม่มีข้อมูลต่อ; Ctrl+D ส่งรหัสนี้ (จบอินพุต) |
ENQ |
Enquiryสอบถาม | 5 | ^E |
— | "Are you there?" request for a response.สัญญาณถามปลายทางว่า "พร้อมไหม" |
ACK |
Acknowledgeตอบรับ | 6 | ^F |
— | "Yes, received / OK" reply.ตอบว่า "รับข้อมูลแล้ว / ตกลง" |
BEL |
Bell / Alertกระดิ่ง | 7 | ^G |
\a |
Makes the terminal beep.สั่งให้เทอร์มินัลส่งเสียงบี๊บ |
BS |
Backspaceถอยหลัง | 8 | ^H |
\b |
Move the cursor back one position.เลื่อนเคอร์เซอร์กลับหนึ่งตำแหน่ง |
HT |
Horizontal Tabแท็บแนวนอน | 9 | ^I |
\t |
Jump to the next tab stop.เลื่อนไปยังตำแหน่งแท็บถัดไป |
LF |
Line Feedป้อนบรรทัด | 10 | ^J |
\n |
Newline; end of a line on Linux and macOS.ขึ้นบรรทัดใหม่; ตัวจบบรรทัดบน Linux และ macOS |
VT |
Vertical Tabแท็บแนวตั้ง | 11 | ^K |
\v |
Move down to the next vertical tab stop.เลื่อนลงไปยังตำแหน่งแท็บแนวตั้งถัดไป |
FF |
Form Feedป้อนหน้า | 12 | ^L |
\f |
Tell a printer to move to a new page.สั่งให้เครื่องพิมพ์เลื่อนไปหน้าถัดไป |
CR |
Carriage Returnปัดแคร่ | 13 | ^M |
\r |
Move the cursor to the start of the line. Windows ends a line with CR + LF.เลื่อนเคอร์เซอร์ไปต้นบรรทัด; Windows จบบรรทัดด้วย CR + LF |
SO |
Shift Outสลับออก | 14 | ^N |
— | Switch to an alternate character set.สลับไปใช้ชุดอักขระสำรอง |
SI |
Shift Inสลับเข้า | 15 | ^O |
— | Switch back to the standard character set.สลับกลับมาใช้ชุดอักขระมาตรฐาน |
DLE |
Data Link Escapeหลีกลิงก์ข้อมูล | 16 | ^P |
— | Changes the meaning of the bytes that follow.เปลี่ยนความหมายของไบต์ที่ตามมา |
DC1 |
Device Control 1 (XON)ควบคุมอุปกรณ์ 1 | 17 | ^Q |
— | Resume transmission (XON) in software flow control.สั่งให้ส่งข้อมูลต่อ (XON) ในการควบคุมการไหลแบบซอฟต์แวร์ |
DC2 |
Device Control 2ควบคุมอุปกรณ์ 2 | 18 | ^R |
— | General device-control signal.สัญญาณควบคุมอุปกรณ์ทั่วไป |
DC3 |
Device Control 3 (XOFF)ควบคุมอุปกรณ์ 3 | 19 | ^S |
— | Pause transmission (XOFF).สั่งให้หยุดส่งข้อมูลชั่วคราว (XOFF) |
DC4 |
Device Control 4ควบคุมอุปกรณ์ 4 | 20 | ^T |
— | General device-control signal, often "stop".สัญญาณควบคุมอุปกรณ์ มักหมายถึง "หยุด" |
NAK |
Negative Acknowledgeตอบปฏิเสธ | 21 | ^U |
— | "Not received / error" reply.ตอบว่า "ไม่ได้รับ / ผิดพลาด" |
SYN |
Synchronous Idleซิงก์ว่าง | 22 | ^V |
— | Filler sent to keep two devices in sync.ไบต์เติมเพื่อรักษาการซิงก์ระหว่างอุปกรณ์ |
ETB |
End of Transmission Blockจบบล็อกการส่ง | 23 | ^W |
— | Marks the end of a block of data.จุดสิ้นสุดของบล็อกข้อมูลหนึ่งบล็อก |
CAN |
Cancelยกเลิก | 24 | ^X |
— | The data that came before was wrong — ignore it.ข้อมูลก่อนหน้าผิด ให้ยกเลิก |
EM |
End of Mediumจบสื่อ | 25 | ^Y |
— | End of the usable part of a tape or disk.จุดสิ้นสุดของส่วนที่ใช้ได้บนเทปหรือดิสก์ |
SUB |
Substituteแทนที่ | 26 | ^Z |
— | Replaces a character that was damaged or invalid. Ctrl+Z on Windows.ใช้แทนอักขระที่เสียหรือไม่ถูกต้อง; Ctrl+Z บน Windows |
ESC |
Escapeหลีก | 27 | ^[ |
\x1b |
Starts a control sequence, e.g. terminal colours and cursor moves.เริ่มลำดับควบคุม เช่น รหัสสีและการย้ายเคอร์เซอร์ในเทอร์มินัล |
FS |
File Separatorคั่นไฟล์ | 28 | ^\ |
— | Separates files in a data stream (largest unit).คั่นระหว่างไฟล์ในสายข้อมูล (หน่วยใหญ่สุด) |
GS |
Group Separatorคั่นกลุ่ม | 29 | ^] |
— | Separates groups of records.คั่นระหว่างกลุ่มของระเบียน |
RS |
Record Separatorคั่นระเบียน | 30 | ^^ |
— | Separates records within a group.คั่นระหว่างระเบียนในกลุ่มเดียวกัน |
US |
Unit Separatorคั่นหน่วย | 31 | ^_ |
— | Separates fields within a record (smallest unit).คั่นระหว่างฟิลด์ในระเบียน (หน่วยเล็กสุด) |
SP |
Spaceช่องว่าง | 32 | — | — | Not a control code — the first printable character, shown here to mark the end of the control range.ไม่ใช่รหัสควบคุม แต่เป็นอักขระพิมพ์ได้ตัวแรก ใส่ไว้เพื่อให้เห็นจุดสิ้นสุดของช่วงควบคุม |
DEL |
Deleteลบ | 127 | ^? |
— | Originally punched out every hole on paper tape to erase a character; today the Delete key.เดิมใช้เจาะรูทุกช่องบนเทปกระดาษเพื่อลบอักขระ ปัจจุบันคือปุ่ม Delete |
Form A is caret notation: ^ followed by
chr(code + 64), so code 10 becomes ^J. Text editors and terminals
use it to show control characters. Form B is the escape sequence used
inside C and Python string literals — a backslash plus a letter, e.g. "\n". Only
the common codes have a short escape; for the rest, write \xHH
(ESC is \x1b) or an octal \NNN. A dash (—) means that form is
not defined for the code.
แบบ A คือ caret notation (สัญกรณ์แคเรต): ^ ตามด้วย
chr(รหัส + 64) ดังนั้นรหัส 10 กลายเป็น ^J
โปรแกรมแก้ไขข้อความและเทอร์มินัลใช้รูปแบบนี้แสดงอักขระควบคุม
แบบ B คือ escape sequence (ลำดับอักขระหลีก) ที่ใช้ในสตริงของภาษา C และ Python
— เครื่องหมาย backslash ตามด้วยตัวอักษร เช่น "\n" มีเฉพาะรหัสที่ใช้บ่อยเท่านั้น
รหัสอื่นเขียนด้วย \xHH (ESC คือ \x1b) หรือเลขฐานแปด \NNN
เครื่องหมายขีด (—) หมายถึงไม่มีรูปแบบนั้นสำหรับรหัสนั้น
Source of Tables 1–2: RFC 20 — ASCII Format for Network Interchange; Wikipedia — ASCII (printable chart, plus control-code names and meanings). ที่มาของตารางที่ 1–2: RFC 20 — ASCII Format for Network Interchange; Wikipedia — ASCII (ตารางอักขระพิมพ์ได้และอักขระควบคุม รวมถึงความหมายของรหัสควบคุม)
3 Codes with ord()
3 ดูรหัสด้วย ord()
ord("A"), ord("a"), and ord("0") return the denary ASCII codes
for uppercase A, lowercase a, and digit zero.
ord("A"), ord("a") และ ord("0") คืนรหัส ASCII ฐานสิบ
ของ A ตัวใหญ่, a ตัวเล็ก และเลขศูนย์
65 97 48
4 Characters with chr()
4 แปลงรหัสเป็นตัวอักษรด้วย chr()
chr(65) is A. chr(32) is a space.
chr(10) is LF (line feed), a control character — not a printable symbol,
so it prints as an empty line.
chr(65) ได้ A ส่วน chr(32) คือช่องว่าง
chr(10) คือ LF (ขึ้นบรรทัดใหม่) ซึ่งเป็นตัวอักษรควบคุม ไม่ใช่สัญลักษณ์ที่พิมพ์ได้
จึงแสดงเป็นบรรทัดว่าง
A
5 One code in denary, binary, and hex 5 รหัสเดียวในฐานสิบ ฐานสอง และฐานสิบหก
Start from denary code 65, then show bin(code), hex(code), and chr(code).
The same character appears in every useful base.
เริ่มจากรหัสฐานสิบ 65 แล้วแสดง bin(code), hex(code) และ chr(code)
ตัวอักษรเดียวกันปรากฏได้ในทุกฐานที่ใช้บ่อย
65 0b1000001 0x41 A
Note: Run uses a JavaScript simulator, not real Python. For real Python, try Google Colab. หมายเหตุ: ปุ่ม Run จำลองด้วย JavaScript ไม่ใช่ Python จริง หากต้องการ Python จริง ลองใช้ Google Colab
References References / แหล่งอ้างอิง
Sources used for ASCII encoding:
แหล่งที่ใช้ประกอบเนื้อหาการเข้ารหัส ASCII:
- ASCII — Wikipedia — ASCII (7-bit range, control vs printable) (ช่วง 7 บิต ตัวควบคุมกับที่พิมพ์ได้)
- ASCII table (0–127) — RFC 20 — ASCII Format for Network Interchange (source of Table 1 in this lesson) (ที่มาของตารางที่ 1 ในบท)
-
Python
ord/chr— Built-in Functions — ord / chr (used in the demos) (ใช้ในตัวอย่าง Run)