Show ASCII table: Difference between revisions

m (→‎{{header|J}}: cleaner, maybe easier to read)
Line 3,316:
116: t 117: u 118: v 119: w 120: x 121: y
122: z 123: { 124: | 125: } 126: ~ 127: Del
</pre>
You could also do this:<br />
<syntaxhighlight lang="java">
String printASCIITable() {
StringBuilder string = new StringBuilder();
String newline = System.lineSeparator();
string.append("dec hex binary oct char").append(newline);
for (int decimal = 32; decimal <= 127; decimal++) {
string.append(format(decimal));
switch (decimal) {
case 32 -> string.append("[SPACE]");
case 127 -> string.append("[DELETE]");
default -> string.append((char) decimal);
}
string.append(newline);
}
return string.toString();
}
 
String format(int value) {
return "%-3d %01$-2x %7s %01$-3o ".formatted(value, Integer.toBinaryString(value));
}
</syntaxhighlight>
<pre>
dec hex binary oct char
32 20 100000 40 [SPACE]
33 21 100001 41 !
34 22 100010 42 "
35 23 100011 43 #
36 24 100100 44 $
37 25 100101 45 %
38 26 100110 46 &
39 27 100111 47 '
40 28 101000 50 (
41 29 101001 51 )
42 2a 101010 52 *
43 2b 101011 53 +
44 2c 101100 54 ,
45 2d 101101 55 -
46 2e 101110 56 .
47 2f 101111 57 /
48 30 110000 60 0
49 31 110001 61 1
50 32 110010 62 2
51 33 110011 63 3
52 34 110100 64 4
53 35 110101 65 5
54 36 110110 66 6
55 37 110111 67 7
56 38 111000 70 8
57 39 111001 71 9
58 3a 111010 72 :
59 3b 111011 73 ;
60 3c 111100 74 <
61 3d 111101 75 =
62 3e 111110 76 >
63 3f 111111 77 ?
64 40 1000000 100 @
65 41 1000001 101 A
66 42 1000010 102 B
67 43 1000011 103 C
68 44 1000100 104 D
69 45 1000101 105 E
70 46 1000110 106 F
71 47 1000111 107 G
72 48 1001000 110 H
73 49 1001001 111 I
74 4a 1001010 112 J
75 4b 1001011 113 K
76 4c 1001100 114 L
77 4d 1001101 115 M
78 4e 1001110 116 N
79 4f 1001111 117 O
80 50 1010000 120 P
81 51 1010001 121 Q
82 52 1010010 122 R
83 53 1010011 123 S
84 54 1010100 124 T
85 55 1010101 125 U
86 56 1010110 126 V
87 57 1010111 127 W
88 58 1011000 130 X
89 59 1011001 131 Y
90 5a 1011010 132 Z
91 5b 1011011 133 [
92 5c 1011100 134 \
93 5d 1011101 135 ]
94 5e 1011110 136 ^
95 5f 1011111 137 _
96 60 1100000 140 `
97 61 1100001 141 a
98 62 1100010 142 b
99 63 1100011 143 c
100 64 1100100 144 d
101 65 1100101 145 e
102 66 1100110 146 f
103 67 1100111 147 g
104 68 1101000 150 h
105 69 1101001 151 i
106 6a 1101010 152 j
107 6b 1101011 153 k
108 6c 1101100 154 l
109 6d 1101101 155 m
110 6e 1101110 156 n
111 6f 1101111 157 o
112 70 1110000 160 p
113 71 1110001 161 q
114 72 1110010 162 r
115 73 1110011 163 s
116 74 1110100 164 t
117 75 1110101 165 u
118 76 1110110 166 v
119 77 1110111 167 w
120 78 1111000 170 x
121 79 1111001 171 y
122 7a 1111010 172 z
123 7b 1111011 173 {
124 7c 1111100 174 |
125 7d 1111101 175 }
126 7e 1111110 176 ~
127 7f 1111111 177 [DELETE]
</pre>
 
118

edits