Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
工程師一定要懂的 Text Encoding
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Inndy
December 18, 2020
Technology
780
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
工程師一定要懂的 Text Encoding
Inndy
December 18, 2020
More Decks by Inndy
See All by Inndy
資訊安全:麻瓜的黑魔法防禦術
inndy
3
3.1k
HackmeCTF 平台背後的心酸血淚史
inndy
2
880
COSCUP 2018 Lightning Talk - 審稿好難,所以我們來寫程式吧
inndy
0
500
逆向工程:從入門到放棄
inndy
7
3.6k
HITCON 2017 Zeroday 發表會
inndy
0
1.4k
No More Crypto Fails
inndy
34
8.3k
你再共用密碼啊
inndy
1
800
CTF From Zero To One
inndy
5
5.3k
逆向工程基礎
inndy
4
1.5k
Other Decks in Technology
See All in Technology
凡エンジニアがこの先生きのこるためには。〜TypeScript完全に理解したい〜
alchemy1115
2
300
シンガポールで登壇してきます
yama3133
0
230
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
110k
AI Coding Agent時代のcdk-nagガードレール 〜組織ルールを強制CIで守り抜く設計の挑戦〜
mhrtech
3
340
関数型の考えを TypeScript に持ち込んで、テストしやすい純粋関数を増やす / Pure at the Core, Effects at the Edge: Bringing Functional Thinking into TypeScript
kaminashi
2
130
Devsumi 2026 Summer 人もAIも使える共通基盤を事業の加速装置にする~デザインシステム運用に学ぶ組織レバレッジ~ 渡辺 凌央
legalontechnologies
PRO
1
200
Foxgloveについて 実際にExtensionを開発して公開するまでの話 / About Foxglove: The Story of Developing and Releasing an Extension
ry0_ka
0
290
OPENLOGI Company Profile for engineer
hr01
1
74k
AI時代のYAGNI:「爆速で無駄になった機能」からの学び / 20260720 Naoki Takahashi
shift_evolve
PRO
2
240
Making sense of Google’s agentic dev tools
glaforge
1
260
DatabricksにおけるMCPソリューション
taka_aki
1
270
“それは自分の仕事じゃない"を越えて行け
yuukiyo
1
430
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
2
1.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Crafting Experiences
bethany
1
210
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
WCS-LA-2024
lcolladotor
0
710
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
320
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
650
Automating Front-end Workflow
addyosmani
1370
210k
HDC tutorial
michielstock
2
740
Code Review Best Practice
trishagee
74
20k
Transcript
Creative Commons 3.0 BY-NC-ND 工程師一定要懂的 Text Encoding 都 2 0
2 0 了 你 還 搞 不 懂 U n i c o d e 嗎 ? Inndy Lin /
[email protected]
奧義智慧 Proprietary and Confidential Information 電腦如何儲存文字?
Creative Commons 3.0 BY-NC-ND ASCII 編碼 ► ASCII 定義 0x00
~ 0x7F ► Printable 0x20 ~ 0x7e ► ' ': 0x20 ► A: 0x41 ► a: 0x61 ► Q: 轉換大小寫快速做法 ► Ans: c ^ 0x20
Creative Commons 3.0 BY-NC-ND ASCII Escape Character ► 0x00 ~
0x1F, 0x7F ► GUI 被發明/普及以前,用 Terminal 跟 Printer ► 為什麼 Windows ( CR LF / "\r\n" ) 換行跟 Linux ( LF "\n" ) 換行不一樣? ► CR 移動遊標到行頭 ► LF 移動遊標到下一行至於為什麼 Linux 只有 LF 我就不知道了 XD
奧義智慧 Proprietary and Confidential Information 歐洲人怎麼辦?
Creative Commons 3.0 BY-NC-ND Latin-1 編碼 ► ASCII 定義範圍 0x00
~ 0x7F ► E(xtended)ASCII 0x00 ~ 0xFF ► a.k.a. ► Latin-1 ► ISO/IEC 8859-1 ► CP 437 ► Python Hack: 用 latin1 編碼可以保存任何 binary data ► b"\x01\x02\x80\xff".decode("latin1")
奧義智慧 Proprietary and Confidential Information 亞洲人怎麼辦?
Creative Commons 3.0 BY-NC-ND CCCII, CSIC, CISCII, …??? Big5!!! ►
電腦發明後,臺灣自己做了幾套中文系統 ► 倚天中文系統、IBM 5550、王安碼 ► 細節我不清楚,畢竟時候我還沒出生 XD ► 資策會把廠商找來開會,指定出大五碼(五家廠商),也就是 Big5,後來也被香港採用 ► 後來 Big5 有改版,新增一些文字,Python 裡面的 Big5 是很早期的標準,所以會缺字 ► 中國自己做了 GBK ► 香港基於 Big5 做了 HKSCS ► Python Tips: 解碼中文請用 "big5-hkscs"
奧義智慧 Proprietary and Confidential Information 同一份文件要放 兩種語言要怎麼辦?
Creative Commons 3.0 BY-NC-ND Unicode! ► 1991 年制訂了 Unicode 1.0
► 除了各國文字外,也包含了 Emoji ► 2020/3 Unicode 13.0 Bubble Tea Emoji! → ► Windows NT: UCS-2 ► Windows XP: UTF-16 ► UTF-8 ► ASCII 的超集合,0x00 ~ 0x7f 相容與 ASCII ► RLE (Running Length Encode) ► 中文字通常佔 3bytes ⚫ 但是 Big5, UTF16 中文只要 2bytes
Creative Commons 3.0 BY-NC-ND Charset, Encoding? ► Charset 定義了有那些符號可以用(Character, Symbol)
► Encoding 是如何把 Character 儲存成 binary 的編碼方式 ► Big5 包含 Charset 以及 Encoding ► Unicode 是 Charset, UTF-8 是 Encoding ► UTF-16 其實有兩種,UTF-16LE, UTF-16BE ► BOM (Byte-Order Mark): 在檔案開頭放一個 U+FEFF 的 character ► PHP → Warning: Cannot modify header information – headers already sent
Creative Commons 3.0 BY-NC-ND Integer Encoding ► Little Endian ►
int a = 0x12345678; ► 在記憶體 / 檔案中: 78 56 34 12 ► UTF-16LE ► >>> chr(0x2266).encode('utf-16le').hex() ► '6622' ► >>> chr(0x2266).encode('utf-16').hex() # with BOM ► 'fffe6622'
Creative Commons 3.0 BY-NC-ND Unicode 編碼黑魔法 ► Unicode 的 Code
point 超過一個 char / wchar_t 的時候 ► UTF-8:一個中文字佔用 3 bytes,Emoji 佔用 4 bytes ► UTF-16 有時候會用 4bytes 表達一個 character
Creative Commons 3.0 BY-NC-ND Unicode - Surrogate Pairs
Creative Commons 3.0 BY-NC-ND 延伸閱讀 ► http://utf8everywhere.org/ ← 非常推薦 ►
https://www.meziantou.net/how-to-correctly-count-the-number-of-characters-of- a-string.htm ► https://github.com/tonsky/FiraCode ► https://speakerdeck.com/inndy/binary-processing
Creative Commons 3.0 BY-NC-ND 延伸閱讀 ► https://en.wikipedia.org/wiki/Unicode ► https://en.wikipedia.org/wiki/UTF-8 ►
https://en.wikipedia.org/wiki/UTF-16 ► https://en.wikipedia.org/wiki/Emoji ► https://en.wikipedia.org/wiki/Big5 ► https://en.wikipedia.org/wiki/Code_page_950
Creative Commons 3.0 BY-NC-ND 延伸閱讀 ► https://www.ptt.cc/bbs/Python/M.1467340705.A.2F5.html ► https://docs.python.org/3.5/library/codecs.html#standard-encodings