作为一名程序员,或多或少的都会和 ASCII 打交道,ASCII 作为一种早期的编码方案,可以说在计算机中是无处不在的。
之前在查看 ASCII 时都是临时 Google 一下,显得有些麻烦,Emacs 能不能帮我们简化这个问题呢,答案是肯定的:
(list-charset-chars 'ascii)
上面这个命令会输出:
0 1 2 3 4 5 6 7 8 9 A B C D E F
0x C-@ C-a C-b C-c C-d C-e C-f C-g C-h TAB C-j C-k C-l RET C-n C-o
1x C-p C-q C-r C-s C-t C-u C-v C-w C-x C-y C-z ESC C-\ C-] C-^ C-_
2x ! " # $ % & ' ( ) * + , - . /
3x 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4x @ A B C D E F G H I J K L M N O
5x P Q R S T U V W X Y Z [ \ ] ^ _
6x ` a b c d e f g h i j k l m n o
7x p q r s t u v w x y z { | } ~ DEL
最右边一列是 8 位 bit 的高四位,最上面一行是 8 位 bit 中的后四位,比如 A 对应的 ASCII 对应的 码就是 41
,转成十进制就是 65 。
还有,通过上面的输出,我们可以清晰的看到 ASCII 码的规律,比如大小写字母是一一对应的,只是相差了 32(对应十六进制的 20)而已.
EmacsWiki[1] 中还有一些增加版,比如:
(defun my/ascii-table ()
"Display basic ASCII table (0 thru 128).
https://ss64.com/ascii.html
https://www.emacswiki.org/emacs/ascii-table.el"
(interactive)
(switch-to-buffer "*ASCII*")
(erase-buffer)
(setq buffer-read-only nil) ;; Not need to edit the content, just read mode (added)
(local-set-key "q" 'bury-buffer) ;; Nice to have the option to bury the buffer (added)
(setq lower32 '("nul" "soh" "stx" "etx" "eot" "enq" "ack" "bel"
"bs" "ht" "nl" "vt" "np" "cr" "so" "si"
"dle" "dc1" "dc2" "dc3" "dc4" "nak" "syn" "etb"
"can" "em" "sub" "esc" "fs" "gs" "rs" "us"
))
(save-excursion (let ((i -1))
(insert "ASCII characters 0 thru 127.\n\n")
(insert " Hex Dec Char| Hex Dec Char| Hex Dec Char| Hex Dec Char\n")
(while (< i 31)
(insert (format "%4x %4d %4s | %4x %4d %4s | %4x %4d %4s | %4x %4d %4s\n"
(setq i (+ 1 i)) i (elt lower32 i)
(setq i (+ 32 i)) i (single-key-description i)
(setq i (+ 32 i)) i (single-key-description i)
(setq i (+ 32 i)) i (single-key-description i)))
(setq i (- i 96))))))
它会把十六进制与十进制的 ASCII 码同时打印出来。
[1]
EmacsWiki: https://www.emacswiki.org/emacs/AsciiTable