ASCII(애스키)란 American Standard Code for Information Interchange의 줄임글로서, 영문자에 기초한 문자 인코딩이다.  이 문자 인코딩에는 C0 제어문자(C0 control character)도 포함되어 있다.  ( 참고:  ASCII - Wikipedia, the free encyclopedia )

다음은  7bit ASCII 코드표를 만들어 보여주는 Common Lisp 소스 코드이다. 소스 코드 중에 진법변환에 필요한 함수

        ()convertItoA number  radix)

의 구현도 포함되어 있다.

(아래의 소스는 CLisp으로 실행된다.)


  1. ;;  Filename: makeAsciiTable.lsp
  2. ;;            Make a table of ascii codes.
  3. ;;
  4. ;;  Execute: clisp makeAsciiTable.lsp
  5. ;;
  6. ;;      Date:  2013.9. 5.
  7. (setf *BASE36* "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  8. (defun printUsage()
  9.     (format t "Usage: lisp makeAsciiTable.lsp~%")
  10.     (format t "Make a table of ascii codes.~%") )
  11. (defun join-string-list (string-list)
  12.     ; (format nil "~{~A~^ ~}" string-list))
  13.     (format nil "~{~A~^~}" string-list))
  14. (defun to-right-align(s)
  15.     (let* ((n (length s))
  16.            (a (get-token s))
  17.            (k (length a)))
  18.          (if (= n 0) s)
  19.          (concatenate 'string (substring s k n) a) ))
  20. (defun get-token (s)
  21.   (let* ((i (if (find (elt s 0) "+-") 1 0))
  22.          (d (position-if 'nonwhite-char-p s :start i))
  23.          (f 0))
  24.     (if (equal d nil) s
  25.            (progn
  26.                (setf f (position-if 'white-char-p s :start (1+ d)))
  27.                (if (equal f nil) s
  28.                    (progn 
  29.                         (substring s d f) )) )) ))
  30. (defun nonwhite-char-p (c)
  31.     (> (char-code c) (char-code #\Space)))
  32. (defun white-char-p (c)
  33.     (<= (char-code c) (char-code #\Space)))
  34. (defun convertItoA(num radix)
  35.     (let* ((isNegative nil)
  36.            (a 0)
  37.            (arr (list))
  38.            (q 0)
  39.            (r 0))
  40.         (if (equal radix nil) (setf radix 10))
  41.         (if (minusp num) (progn
  42.             (setf isNegative t)
  43.             (setf inum (- num)) ))
  44.         (setf q num)
  45.         (loop while (>= q radix) do
  46.             (setf r (mod q radix))
  47.             (setf q (floor (/ q radix))) 
  48.             (setf arr (nconc arr (list (substring *BASE36* r (1+ r)))))
  49.         )
  50.        (setf arr (nconc arr (list (substring *BASE36* q (1+ q)))))
  51.        (if isNegative (nconc (ncons arr (list "-"))) )
  52.        (setf arr (reverse arr))
  53.        (join-string-list arr)
  54.     )
  55. )
  56. (setf *asc* (list
  57.     "NUL" "SOH"  "STX"  "ETX"  "EOT"
  58.     "ENQ" "ACK"  "BEL"  "BS"   "HT"
  59.     "LF"  "VT"   "FF"   "CR"   "SO"
  60.     "SI"  "DLE"  "DC1"  "DC2"  "DC3"
  61.     "DC4" "NAK"  "SYN"  "ETB"  "CAN"
  62.     "EM"  "SUB"  "ESC"  "FS"   "GS"
  63.     "RS"  "US"   "Spc"
  64.     ))
  65. (setf *control* (list
  66.     "NUL (null)"
  67.     "SOH (start of heading)"
  68.     "STX (start of text)"
  69.     "ETX (end of text)"
  70.     "EOT (end of transmission)"
  71.     "ENQ (enquiry)"
  72.     "ACK (acknowledge)"
  73.     "BEL (bell)"
  74.     "BS  (backspace)"
  75.     "TAB (horizontal tab)"
  76.     "LF  (line feed, NL new line)"
  77.     "VT  (vertical tab)"
  78.     "FF  (form feed, NP new page)"
  79.     "CR  (carriage return)"
  80.     "SO  (shift out)"
  81.     "SI  (shift in)"
  82.     "DLE (data link escape)"
  83.     "DC1 (device control 1)"
  84.     "DC2 (device control 2)"
  85.     "DC3 (device control 3)"
  86.     "DC4 (device control 4)"
  87.     "NAK (negative acknowledge)"
  88.     "SYN (synchronous idle)"
  89.     "ETB (end of trans. block)"
  90.     "CAN (cancel)"
  91.     "EM  (end of medium)"
  92.     "SUB (substitute, EOF end of file)"
  93.     "ESC (escape)"
  94.     "FS  (file separator)"
  95.     "GS  (group separator)"
  96.     "RS  (record separator)"
  97.     "US  (unit separator)"
  98.     ))
  99. (defun makeTable()
  100.     (let* ((sbuf "")
  101.            (abuf "")
  102.            (tbuf "")
  103.            (c #\Space))
  104.         (setf sbuf "    ")
  105.         (loop for i from 0 below 8 do
  106.             (setf sbuf (concatenate 'string sbuf "+----")))
  107.         (setf sbuf (concatenate 'string sbuf "+"))
  108.         (format t "~A~%" sbuf)
  109.         (setf sbuf "    ")
  110.         (setf sbuf (concatenate 'string sbuf "| 0- "))
  111.         (setf sbuf (concatenate 'string sbuf "| 1- "))
  112.         (setf sbuf (concatenate 'string sbuf "| 2- "))
  113.         (setf sbuf (concatenate 'string sbuf "| 3- "))
  114.         (setf sbuf (concatenate 'string sbuf "| 4- "))
  115.         (setf sbuf (concatenate 'string sbuf "| 5- "))
  116.         (setf sbuf (concatenate 'string sbuf "| 6- "))
  117.         (setf sbuf (concatenate 'string sbuf "| 7- "))
  118.         (setf sbuf (concatenate 'string sbuf "|"))
  119.         (format t "~A~%" sbuf)
  120.         (setf sbuf "+---")
  121.         (loop for i from 0 below 8 do
  122.             (setf sbuf (concatenate 'string sbuf "+----")))
  123.         (setf sbuf (concatenate 'string sbuf "+"))
  124.         (format t "~A~%" sbuf)
  125.         (loop for i from 0 below 16 do
  126.             (setf tbuf "")
  127.             (setf sbuf (convertItoA i 16))
  128.             (setf tbuf (concatenate 'string "| " sbuf " "))
  129.             (loop for j from 0 below 8 do
  130.                 (if (<= (+ (* j 16) i)  32)
  131.                     (setf abuf (format nil "| ~3A" (nth (+ (* j 16) i) *asc*)))
  132.                     (if (= (+ (* j 16) i)  127)
  133.                         (setf abuf (format nil "| ~3A" "DEL"))
  134.                         (progn
  135.                             (setf c (code-char (+ (* j 16) i)))
  136.                             (setf abuf (format nil "|  ~2A" c)) )))
  137.                 (setf tbuf (concatenate 'string tbuf abuf))
  138.             )
  139.             (setf tbuf (concatenate 'string tbuf "|"))
  140.             (format t "~A~%" tbuf)
  141.         )
  142.         (setf sbuf "+---")
  143.         (loop for i from 0 below 8 do
  144.             (setf sbuf (concatenate 'string sbuf "+----")))
  145.         (setf sbuf (concatenate 'string sbuf "+"))
  146.         (format t "~A~%" sbuf)
  147.         (format t "~%")
  148.         (loop for i from 0 below 16 do
  149.             (setf tbuf (format nil "~30A  ~34A" (nth i *control*) (nth (+ i 16) *control*)))
  150.             (format t "~A~%" tbuf)
  151.         )
  152.     ))
  153. (if (and (> (length ext:*args*) 0) (equal (nth 0 ext:*args*) "-h")) (progn
  154.     (printUsage)
  155.     (quit) ))
  156. (makeTable)




실행> clisp makeAsciiTable.lsp

   
    +----+----+----+----+----+----+----+----+
    | 0- | 1- | 2- | 3- | 4- | 5- | 6- | 7- |
+---+----+----+----+----+----+----+----+----+
| 0 | NUL| DLE| Spc|  0 |  @ |  P |  ` |  p |
| 1 | SOH| DC1|  ! |  1 |  A |  Q |  a |  q |
| 2 | STX| DC2|  " |  2 |  B |  R |  b |  r |
| 3 | ETX| DC3|  # |  3 |  C |  S |  c |  s |
| 4 | EOT| DC4|  $ |  4 |  D |  T |  d |  t |
| 5 | ENQ| NAK|  % |  5 |  E |  U |  e |  u |
| 6 | ACK| SYN|  & |  6 |  F |  V |  f |  v |
| 7 | BEL| ETB|  ' |  7 |  G |  W |  g |  w |
| 8 | BS | CAN|  ( |  8 |  H |  X |  h |  x |
| 9 | HT | EM |  ) |  9 |  I |  Y |  i |  y |
| A | LF | SUB|  * |  : |  J |  Z |  j |  z |
| B | VT | ESC|  + |  ; |  K |  [ |  k |  { |
| C | FF | FS |  , |  < |  L |  \ |  l |  | |
| D | CR | GS |  - |  = |  M |  ] |  m |  } |
| E | SO | RS |  . |  > |  N |  ^ |  n |  ~ |
| F | SI | US |  / |  ? |  O |  _ |  o | DEL|
+---+----+----+----+----+----+----+----+----+

NUL (null)                      DLE (data link escape)
SOH (start of heading)          DC1 (device control 1)
STX (start of text)             DC2 (device control 2)
ETX (end of text)               DC3 (device control 3)
EOT (end of transmission)       DC4 (device control 4)
ENQ (enquiry)                   NAK (negative acknowledge)
ACK (acknowledge)               SYN (synchronous idle)
BEL (bell)                      ETB (end of trans. block)
BS  (backspace)                 CAN (cancel)
TAB (horizontal tab)            EM  (end of medium)
LF  (line feed, NL new line)    SUB (substitute, EOF end of file)
VT  (vertical tab)              ESC (escape)
FF  (form feed, NP new page)    FS  (file separator)
CR  (carriage return)           GS  (group separator)
SO  (shift out)                 RS  (record separator)
SI  (shift in)                  US  (unit separator)




 

Posted by Scripter
,