generate ascii table

$ cat ascii.sh 
dec_count=0

while [ $dec_count -lt 256 ]
do
        echo -e "\x$(echo "ibase=10;obase=16;$dec_count" | bc)\c"
        dec_count=$((dec_count+1))
done

$ bash ascii.sh | hexdump -C
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
00000100

  

$ cat ascii.sh 
dec_count=32

while [ $dec_count -lt 128 ]
do
        times=0
        while [ $times -lt 16 ]
        do
                echo -e "\x$(echo "ibase=10;obase=16;$dec_count" | bc)\c"
                times=$((times+1))
        done
        dec_count=$((dec_count+1))
done

$ bash ascii.sh | hexdump -C | cut -c57-60,64 > ascii_table

$ cat ascii_table 
20   
21  !
22  "
23  #
24  $
25  %
26  &
27  '
28  (
29  )
2a  *
2b  +
2c  ,
2d  -
2e  .
2f  /
30  0
31  1
32  2
33  3
34  4
35  5
36  6
37  7
38  8
39  9
3a  :
3b  ;
3c  <
3d  =
3e  >
3f  ?
40  @
41  A
42  B
43  C
44  D
45  E
46  F
47  G
48  H
49  I
4a  J
4b  K
4c  L
4d  M
4e  N
4f  O
50  P
51  Q
52  R
53  S
54  T
55  U
56  V
57  W
58  X
59  Y
5a  Z
5b  [
5c  \
5d  ]
5e  ^
5f  _
60  `
61  a
62  b
63  c
64  d
65  e
66  f
67  g
68  h
69  i
6a  j
6b  k
6c  l
6d  m
6e  n
6f  o
70  p
71  q
72  r
73  s
74  t
75  u
76  v
77  w
78  x
79  y
7a  z
7b  {
7c  |
7d  }
7e  ~
7f  .

[daniel@win-8me2aq586jt Creates message box.53BA45E9]$ 

  

Prelude> zip [0x1..0x7f] ['\x01'..'\x7f']
[(1,'\SOH'),(2,'\STX'),(3,'\ETX'),(4,'\EOT'),(5,'\ENQ'),(6,'\ACK'),(7,'\a'),(8,'\b'),(9,'\t'),(10,'\n'),(11,'\v'),(12,'\f'),(13,'\r'),(14,'\SO'),(15,'\SI'),(16,'\DLE'),(17,'\DC1'),(18,'\DC2'),(19,'\DC3'),(20,'\DC4'),(21,'\NAK'),(22,'\SYN'),(23,'\ETB'),(24,'\CAN'),(25,'\EM'),(26,'\SUB'),(27,'\ESC'),(28,'\FS'),(29,'\GS'),(30,'\RS'),(31,'\US'),(32,' '),(33,'!'),(34,'"'),(35,'#'),(36,'$'),(37,'%'),(38,'&'),(39,'\''),(40,'('),(41,')'),(42,'*'),(43,'+'),(44,','),(45,'-'),(46,'.'),(47,'/'),(48,'0'),(49,'1'),(50,'2'),(51,'3'),(52,'4'),(53,'5'),(54,'6'),(55,'7'),(56,'8'),(57,'9'),(58,':'),(59,';'),(60,'<'),(61,'='),(62,'>'),(63,'?'),(64,'@'),(65,'A'),(66,'B'),(67,'C'),(68,'D'),(69,'E'),(70,'F'),(71,'G'),(72,'H'),(73,'I'),(74,'J'),(75,'K'),(76,'L'),(77,'M'),(78,'N'),(79,'O'),(80,'P'),(81,'Q'),(82,'R'),(83,'S'),(84,'T'),(85,'U'),(86,'V'),(87,'W'),(88,'X'),(89,'Y'),(90,'Z'),(91,'['),(92,'\\'),(93,']'),(94,'^'),(95,'_'),(96,'`'),(97,'a'),(98,'b'),(99,'c'),(100,'d'),(101,'e'),(102,'f'),(103,'g'),(104,'h'),(105,'i'),(106,'j'),(107,'k'),(108,'l'),(109,'m'),(110,'n'),(111,'o'),(112,'p'),(113,'q'),(114,'r'),(115,'s'),(116,'t'),(117,'u'),(118,'v'),(119,'w'),(120,'x'),(121,'y'),(122,'z'),(123,'{'),(124,'|'),(125,'}'),(126,'~'),(127,'\DEL')]

  

daniel@daniel-mint ~/haskell $ cat trizip.hs
import Text.Printf
import Numeric

trizip :: [a] -> [b] -> [c] -> [(a,b,c)]
trizip a b c
	| null a = []
	| null b = []
	| null c = []
trizip (x:xs) (y:ys) (z:zs) = (++) [(x,y,z)] (trizip xs ys zs)

showtuple :: (Int, Char, Int) -> String
showtuple (di, ch, hi) = (show di) ++ "\t0x" ++ (showHex hi "\t") ++ (show ch) ++ "\n"

main = do
	let asciit =  trizip [0x1..0x7f] ['\x01'..'\x7f'] [0x1..0x7f]
	putStr (concat (map showtuple asciit)) 

  

daniel@daniel-mint ~/haskell $ runhaskell trizip.hs
1	0x1	'\SOH'
2	0x2	'\STX'
3	0x3	'\ETX'
4	0x4	'\EOT'
5	0x5	'\ENQ'
6	0x6	'\ACK'
7	0x7	'\a'
8	0x8	'\b'
9	0x9	'\t'
10	0xa	'\n'
11	0xb	'\v'
12	0xc	'\f'
13	0xd	'\r'
14	0xe	'\SO'
15	0xf	'\SI'
16	0x10	'\DLE'
17	0x11	'\DC1'
18	0x12	'\DC2'
19	0x13	'\DC3'
20	0x14	'\DC4'
21	0x15	'\NAK'
22	0x16	'\SYN'
23	0x17	'\ETB'
24	0x18	'\CAN'
25	0x19	'\EM'
26	0x1a	'\SUB'
27	0x1b	'\ESC'
28	0x1c	'\FS'
29	0x1d	'\GS'
30	0x1e	'\RS'
31	0x1f	'\US'
32	0x20	' '
33	0x21	'!'
34	0x22	'"'
35	0x23	'#'
36	0x24	'$'
37	0x25	'%'
38	0x26	'&'
39	0x27	'\''
40	0x28	'('
41	0x29	')'
42	0x2a	'*'
43	0x2b	'+'
44	0x2c	','
45	0x2d	'-'
46	0x2e	'.'
47	0x2f	'/'
48	0x30	'0'
49	0x31	'1'
50	0x32	'2'
51	0x33	'3'
52	0x34	'4'
53	0x35	'5'
54	0x36	'6'
55	0x37	'7'
56	0x38	'8'
57	0x39	'9'
58	0x3a	':'
59	0x3b	';'
60	0x3c	'<'
61	0x3d	'='
62	0x3e	'>'
63	0x3f	'?'
64	0x40	'@'
65	0x41	'A'
66	0x42	'B'
67	0x43	'C'
68	0x44	'D'
69	0x45	'E'
70	0x46	'F'
71	0x47	'G'
72	0x48	'H'
73	0x49	'I'
74	0x4a	'J'
75	0x4b	'K'
76	0x4c	'L'
77	0x4d	'M'
78	0x4e	'N'
79	0x4f	'O'
80	0x50	'P'
81	0x51	'Q'
82	0x52	'R'
83	0x53	'S'
84	0x54	'T'
85	0x55	'U'
86	0x56	'V'
87	0x57	'W'
88	0x58	'X'
89	0x59	'Y'
90	0x5a	'Z'
91	0x5b	'['
92	0x5c	'\\'
93	0x5d	']'
94	0x5e	'^'
95	0x5f	'_'
96	0x60	'`'
97	0x61	'a'
98	0x62	'b'
99	0x63	'c'
100	0x64	'd'
101	0x65	'e'
102	0x66	'f'
103	0x67	'g'
104	0x68	'h'
105	0x69	'i'
106	0x6a	'j'
107	0x6b	'k'
108	0x6c	'l'
109	0x6d	'm'
110	0x6e	'n'
111	0x6f	'o'
112	0x70	'p'
113	0x71	'q'
114	0x72	'r'
115	0x73	's'
116	0x74	't'
117	0x75	'u'
118	0x76	'v'
119	0x77	'w'
120	0x78	'x'
121	0x79	'y'
122	0x7a	'z'
123	0x7b	'{'
124	0x7c	'|'
125	0x7d	'}'
126	0x7e	'~'
127	0x7f	'\DEL'

  

posted @ 2014-07-09 10:48  Daniel King  阅读(410)  评论(0编辑  收藏  举报