Show ASCII table: Difference between revisions
(→{{header|REXX}}: added comments to the REXX section and output headers, changed text for the program's description.) |
m (→{{header|REXX}}: changed manner of presenting the note for the output section.) |
||
Line 1,112: | Line 1,112: | ||
{{out|output}} |
{{out|output}} |
||
Code page '''437''' was used for the example below |
(Code page '''437''' was used for the example below using DOS under Microsoft Windows.) |
||
<pre> |
<pre> |
||
0 1 2 3 4 5 6 7 8 9 A B C D E F |
0 1 2 3 4 5 6 7 8 9 A B C D E F |
Revision as of 01:25, 11 August 2018
- Task
Show ASCII character set from values 32 to 127 in table format.
AppleScript
<lang applescript>-- asciiTable :: () -> String on asciiTable()
script row on |λ|(ln) script cell on |λ|(x) justifyLeft(12, space, x) end |λ| end script concat(map(cell, ln)) end |λ| end script unlines(map(row, ¬ transpose(chunksOf(16, map(my asciiEntry, ¬ enumFromTo(32, 127))))))
end asciiTable
on run
asciiTable()
end run
-- asciiEntry :: Int -> String on asciiEntry(n)
set k to asciiName(n) if "" ≠ k then justifyRight(4, space, n as string) & " : " & k else k end if
end asciiEntry
-- asciiName :: Int -> String on asciiName(n)
if 32 > n or 127 < n then "" else if 32 = n then "Spc" else if 127 = n then "Del" else chr(n) end if
end asciiName
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- chr :: Int -> Char on chr(n)
character id n
end chr
-- chunksOf :: Int -> [a] -> a on chunksOf(k, xs)
script on go(ys) set ab to splitAt(k, ys) set a to |1| of ab if isNull(a) then {} else {a} & go(|2| of ab) end if end go end script result's go(xs)
end chunksOf
-- comparing :: (a -> b) -> (a -> a -> Ordering) on comparing(f)
script on |λ|(a, b) tell mReturn(f) set fa to |λ|(a) set fb to |λ|(b) if fa < fb then -1 else if fa > fb then 1 else 0 end if end tell end |λ| end script
end comparing
-- concat :: a -> [a] -- concat :: [String] -> String on concat(xs)
set lng to length of xs if 0 < lng and string is class of (item 1 of xs) then set acc to "" else set acc to {} end if repeat with i from 1 to lng set acc to acc & item i of xs end repeat acc
end concat
-- concatMap :: (a -> [b]) -> [a] -> [b] on concatMap(f, xs)
set lng to length of xs if 0 < lng and class of xs is string then set acc to "" else set acc to {} end if tell mReturn(f) repeat with i from 1 to lng set acc to acc & |λ|(item i of xs, i, xs) end repeat end tell return acc
end concatMap
-- enumFromTo :: Int -> Int -> [Int] on enumFromTo(m, n)
if m ≤ n then set lst to {} repeat with i from m to n set end of lst to i end repeat return lst else return {} end if
end enumFromTo
-- foldl :: (a -> b -> a) -> a -> [b] -> a on foldl(f, startValue, xs)
tell mReturn(f) set v to startValue set lng to length of xs repeat with i from 1 to lng set v to |λ|(v, item i of xs, i, xs) end repeat return v end tell
end foldl
-- isNull :: [a] -> Bool -- isNull :: String -> Bool on isNull(xs)
if class of xs is string then "" = xs else {} = xs end if
end isNull
-- justifyLeft :: Int -> Char -> String -> String on justifyLeft(n, cFiller, strText)
if n > length of strText then text 1 thru n of (strText & replicate(n, cFiller)) else strText end if
end justifyLeft
-- justifyRight :: Int -> Char -> String -> String on justifyRight(n, cFiller, strText)
if n > length of strText then text -n thru -1 of ((replicate(n, cFiller) as text) & strText) else strText end if
end justifyRight
-- length :: [a] -> Int on |length|(xs)
length of xs
end |length|
-- max :: Ord a => a -> a -> a on max(x, y)
if x > y then x else y end if
end max
-- maximumBy :: (a -> a -> Ordering) -> [a] -> a on maximumBy(f, xs)
set cmp to mReturn(f) script max on |λ|(a, b) if a is missing value or cmp's |λ|(a, b) < 0 then b else a end if end |λ| end script foldl(max, missing value, xs)
end maximumBy
-- Lift 2nd class handler function into 1st class script wrapper -- mReturn :: First-class m => (a -> b) -> m (a -> b) on mReturn(f)
if class of f is script then f else script property |λ| : f end script end if
end mReturn
-- map :: (a -> b) -> [a] -> [b] on map(f, xs)
tell mReturn(f) set lng to length of xs set lst to {} repeat with i from 1 to lng set end of lst to |λ|(item i of xs, i, xs) end repeat return lst end tell
end map
-- Egyptian multiplication - progressively doubling a list, appending -- stages of doubling to an accumulator where needed for binary -- assembly of a target length -- replicate :: Int -> a -> [a] on replicate(n, a)
set out to {} if n < 1 then return out set dbl to {a} repeat while (n > 1) if (n mod 2) > 0 then set out to out & dbl set n to (n div 2) set dbl to (dbl & dbl) end repeat return out & dbl
end replicate
-- splitAt :: Int -> [a] -> ([a],[a]) on splitAt(n, xs)
if n > 0 and n < length of xs then if class of xs is text then Tuple(items 1 thru n of xs as text, items (n + 1) thru -1 of xs as text) else Tuple(items 1 thru n of xs, items (n + 1) thru -1 of xs) end if else if n < 1 then Tuple({}, xs) else Tuple(xs, {}) end if end if
end splitAt
-- If some of the rows are shorter than the following rows, -- their elements are skipped: -- transpose({{10,11},{20},{},{30,31,32}}) -> {{10, 20, 30}, {11, 31}, {32}} -- transpose :: a -> a on transpose(xxs)
set intMax to |length|(maximumBy(comparing(my |length|), xxs)) set gaps to replicate(intMax, {}) script padded on |λ|(xs) set lng to |length|(xs) if lng < intMax then xs & items (lng + 1) thru -1 of gaps else xs end if end |λ| end script set rows to map(padded, xxs) script cols on |λ|(_, iCol) script cell on |λ|(row) item iCol of row end |λ| end script concatMap(cell, rows) end |λ| end script map(cols, item 1 of rows)
end transpose
-- Tuple (,) :: a -> b -> (a, b) on Tuple(a, b)
{type:"Tuple", |1|:a, |2|:b, length:2}
end Tuple
-- unlines :: [String] -> String on unlines(xs)
set {dlm, my text item delimiters} to ¬ {my text item delimiters, linefeed} set str to xs as text set my text item delimiters to dlm str
end unlines</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
C
<lang c>#include <stdio.h>
int main() {
int i, j; char k[4]; for (i = 0; i < 16; ++i) { for (j = 32 + i; j < 128; j += 16) { switch (j) { default: sprintf(k, "%c", j); break; case 32: sprintf(k, "Spc"); break; case 127: sprintf(k, "Del"); break; } printf("%3d : %-3s ", j, k); } printf("\n"); } return 0;
}</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Factor
Idiomatic version
<lang factor>USING: combinators formatting io kernel math math.ranges pair-rocket sequences ; IN: rosetta-code.ascii-table
- row-values ( n -- seq ) [ 32 + ] [ 112 + ] bi 16 <range> ;
- ascii>output ( n -- str )
{ 32 => [ "Spc" ] 127 => [ "Del" ] [ "" 1sequence ] } case ;
- print-row ( n -- )
row-values [ dup ascii>output "%3d : %-3s " printf ] each nl ;
- print-ascii-table ( -- ) 16 <iota> [ print-row ] each ;
MAIN: print-ascii-table</lang>
Go translation
<lang factor>USING: combinators formatting io kernel math math.ranges pair-rocket sequences ; IN: rosetta-code.ascii-table
- main ( -- )
16 <iota> [ 32 + 127 16 <range> [ dup { 32 => [ "Spc" ] 127 => [ "Del" ] [ "" 1sequence ] } case "%3d : %-3s " printf ] each nl ] each
MAIN: main</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Go
<lang go>package main
import "fmt"
func main() {
for i := 0; i < 16; i++ { for j := 32 + i; j < 128; j += 16 { k := string(j) switch j { case 32: k = "Spc" case 127: k = "Del" } fmt.Printf("%3d : %-3s ", j, k) } fmt.Println() }
} </lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Haskell
<lang haskell>import Data.List (intercalate, transpose) import Data.Char (chr)
asciiTable :: String asciiTable =
unlines $ (justifyLeft 12 ' ' =<<) <$> transpose (chunksOf 16 $ asciiEntry <$> [32 .. 127])
main :: IO () main = putStrLn asciiTable
asciiName :: Int -> String asciiName n
| 32 > n = "" | 127 < n = "" | 32 == n = "Spc" | 127 == n = "Del" | otherwise = [chr n]
asciiEntry :: Int -> String asciiEntry n =
let k = asciiName n in if null k then "" else concat [justifyRight 4 ' ' (show n), " : ", k]
chunksOf :: Int -> [a] -> a chunksOf k = go
where go t = case splitAt k t of (a, b) | null a -> [] | otherwise -> a : go b
justifyLeft, justifyRight :: Int -> Char -> String -> String justifyLeft n c s = take n (s ++ replicate n c)
justifyRight n c s = drop (length s) (replicate n c ++ s)</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
JavaScript
<lang javascript>(() => {
// asciiTable :: String const asciiTable = () => unlines( map(xs => concat( map(justifyLeft(12, ' '), xs ) ), transpose( chunksOf( 16, map(asciiEntry, enumFromTo(32, 127) ) ) ) ) );
// asciiEntry :: Int -> String const asciiEntry = n => { const k = asciiName(n); return === k ? ( ) : (justifyRight(4, ' ', n.toString()) + ' : ' + k); };
// asciiName :: Int -> String const asciiName = n => 32 > n || 127 < n ? ( ) : 32 === n ? ( 'Spc' ) : 127 === n ? ( 'Del' ) : chr(n);
// GENERIC FUNCTIONS ----------------------------------
// chunksOf :: Int -> [a] -> a const chunksOf = (n, xs) => xs.reduce((a, _, i, xs) => i % n ? a : a.concat([xs.slice(i, i + n)]), []);
// chr :: Int -> Char const chr = String.fromCodePoint;
// comparing :: (a -> b) -> (a -> a -> Ordering) const comparing = f => (x, y) => { const a = f(x), b = f(y); return a < b ? -1 : (a > b ? 1 : 0); };
// concat :: a -> [a] // concat :: [String] -> String const concat = xs => 0 < xs.length ? (() => { const unit = 'string' !== typeof xs[0] ? ( [] ) : ; return unit.concat.apply(unit, xs); })() : [];
// concatMap :: (a -> [b]) -> [a] -> [b] const concatMap = (f, xs) => 0 < xs.length ? (() => { const unit = 'string' !== typeof xs ? ( [] ) : ; return unit.concat.apply(unit, xs.map(f)) })() : [];
// enumFromTo :: Int -> Int -> [Int] const enumFromTo = (m, n) => m <= n ? iterateUntil( x => n <= x, x => 1 + x, m ) : [];
// iterateUntil :: (a -> Bool) -> (a -> a) -> a -> [a] const iterateUntil = (p, f, x) => { const vs = [x]; let h = x; while (!p(h))(h = f(h), vs.push(h)); return vs; };
// justifyLeft :: Int -> Char -> String -> String const justifyLeft = (n, cFiller) => strText => n > strText.length ? ( (strText + cFiller.repeat(n)) .substr(0, n) ) : strText;
// justifyRight :: Int -> Char -> String -> String const justifyRight = (n, cFiller, strText) => n > strText.length ? ( (cFiller.repeat(n) + strText) .slice(-n) ) : strText;
// length :: [a] -> Int const length = xs => xs.length;
// map :: (a -> b) -> [a] -> [b] const map = (f, xs) => xs.map(f);
// maximumBy :: (a -> a -> Ordering) -> [a] -> a const maximumBy = (f, xs) => 0 < xs.length ? ( xs.slice(1) .reduce((a, x) => 0 < f(x, a) ? x : a, xs[0]) ) : undefined;
// replicate :: Int -> a -> [a] const replicate = (n, x) => Array.from({ length: n }, () => x);
// transpose :: a -> a const transpose = tbl => { const gaps = replicate( length(maximumBy(comparing(length), tbl)), [] ), rows = map(xs => xs.concat(gaps.slice(xs.length)), tbl); return map( (_, col) => concatMap(row => [row[col]], rows), rows[0] ); };
// unlines :: [String] -> String const unlines = xs => xs.join('\n');
// MAIN ----------------------------------------------- return asciiTable();
})();</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Kotlin
<lang scala>// Version 1.2.60
fun main(args: Array<String>) {
for (i in 0..15) { for (j in 32 + i..127 step 16) { val k = when (j) { 32 -> "Spc" 127 -> "Del" else -> j.toChar().toString() } System.out.printf("%3d : %-3s ", j, k) } println() }
}</lang>
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Perl 6
Alternately, and perhaps more usefully, output as a wiki-table rather than ASCII art. Hover mouse over the glyph to get the name.
<lang perl6>sub glyph ($_) {
when * < 33 { (0x2400 + $_).chr } # display symbol names for invisible glyphs when 127 { '␡' } default { .chr }
}
say '{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"';
for (^128).rotor(16) -> @row {
say '|-'; printf(q[|%d
0x%02X
%s] ~ "\n", $_, $_, .&glyph.uniname.subst('SYMBOL FOR ', ), .&glyph.subst('|', '|')) for @row;
}
say '|}';</lang>
- Output:
0 0x00 ␀ |
1 0x01 ␁ |
2 0x02 ␂ |
3 0x03 ␃ |
4 0x04 ␄ |
5 0x05 ␅ |
6 0x06 ␆ |
7 0x07 ␇ |
8 0x08 ␈ |
9 0x09 ␉ |
10 0x0A ␊ |
11 0x0B ␋ |
12 0x0C ␌ |
13 0x0D ␍ |
14 0x0E ␎ |
15 0x0F ␏ |
16 0x10 ␐ |
17 0x11 ␑ |
18 0x12 ␒ |
19 0x13 ␓ |
20 0x14 ␔ |
21 0x15 ␕ |
22 0x16 ␖ |
23 0x17 ␗ |
24 0x18 ␘ |
25 0x19 ␙ |
26 0x1A ␚ |
27 0x1B ␛ |
28 0x1C ␜ |
29 0x1D ␝ |
30 0x1E ␞ |
31 0x1F ␟ |
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 ␡ |
Python
After Perl6, but creating an HTML table: <lang python>from unicodedata import name from html import escape
def pp(n):
if n <= 32: return chr(0x2400 + n) if n == 127: return '␡' return chr(n)
print('
\n ') for n in range(128): if n %16 == 0 and 1 < n: print(" ") print(f' ') print(""" \n{n} 0x{n:02x} {escape(pp(n))} |
""")</lang>
- Output:
0 0x00 ␀ |
1 0x01 ␁ |
2 0x02 ␂ |
3 0x03 ␃ |
4 0x04 ␄ |
5 0x05 ␅ |
6 0x06 ␆ |
7 0x07 ␇ |
8 0x08 ␈ |
9 0x09 ␉ |
10 0x0a ␊ |
11 0x0b ␋ |
12 0x0c ␌ |
13 0x0d ␍ |
14 0x0e ␎ |
15 0x0f ␏ |
16 0x10 ␐ |
17 0x11 ␑ |
18 0x12 ␒ |
19 0x13 ␓ |
20 0x14 ␔ |
21 0x15 ␕ |
22 0x16 ␖ |
23 0x17 ␗ |
24 0x18 ␘ |
25 0x19 ␙ |
26 0x1a ␚ |
27 0x1b ␛ |
28 0x1c ␜ |
29 0x1d ␝ |
30 0x1e ␞ |
31 0x1f ␟ |
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 ␡ |
REXX
Note that some REXX interpreters can't display
the '1b'x (esc) character glyph properly, so a special check was
made for those two REXXes to not show that glyph.
A fair amount of code was added to show all possible characters (glyphs), with special attention paid to:
- presenting an index (top and bottom; left and right).
- using a grid instead of using blanks for visual fidelity.
- using a two─tired type of grid (with single─ and double─lined cells).
- preserving indentation and other whitespace.
- showing the function of some characters (lower value than a blank).
- showing the name of a blank (as bla).
- the suppression of displaying particular glyphs by REXX that are preempted by the OS.
- adding homage to the adage of: anything worth doing is worth doing well.
<lang rexx>/*REXX program displays an ASCII table of characters (within a 16x16 indexed grid).*/ parse upper version !ver . /*some REXXes can't display '1b'x glyph*/ !pcRexx= 'REXX/PERSONAL'==!ver | 'REXX/PC'==!ver /*is this PC/REXX or REXX/Personal? */
func= ' nul soh stx etx eot enq ack bel bs tab lf vt ff cr so si ' || , " dle dc1 dc2 dc3 dc4 nak syn etb can em eof esc fs gs rs us "
hdr= left(, 7) /*prepend blanks to HDR (indentation).*/ call xhdr /*construct a top index for the grid.*/ call grid '╔', "╤", '╗', "═══" /*construct & display bottom of a cell.*/ iidx= left(, length(hdr) - 4) /*the length of the indentation of idx.*/ cant= copies('═', 3) /*can't show a character with this REXX*/
/* [↓] construct a sixteen-row grid. */ do j=0 by 16 for 16; idx= left(d2x(j),1,2) /*prepend an index literal for the grid*/ _= iidx idx ' '; _h= iidx " " /*an index and indent; without an index*/ sep= '║' /*assign a character to cell separator.*/ do #=j to j+15; chr= center( d2c(#), 3) /*true char glyph.*/ if #>6 & #<11 | #==13 then chr= cant /*can't show these glyphs.*/ /*esc*/ if #==27 then if !pcRexx then chr= cant /* " " this glyph. */ else chr= center( '1b'x, 3) /*true char glyph.*/ if # <32 then _h= _h || sep || right(word(func, #+1), 3) /*show a function.*/ if #==32 then chr= 'bla' /*spell out (within 3 chars) a "blank".*/ if # >31 then _h= /*Above a blank? Then nullify 3rd line*/ _= _ || sep || chr; sep= '│' /*append grid cell; use a new sep char.*/ end /*#*/ if _h\== then say _h'║ ' /*append the last grid cell character.*/ say _'║ ' idx /*append an index to the grid line.*/ if j\==240 then call grid '╟',"┼",'╢','───' /*construct & display most cell bottoms*/ end /*j*/
call grid '╚', "╧", '╝', "═══" /*construct & display last cell bottom.*/ call xhdr /*construct a bottom index for the grid*/ exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ xhdr: say; _=hdr; sep=' '; do k=0 for 16; _=_' ' d2x(k)" "; end; say _; say; return grid: arg $1,$2,$3,$4;_=hdr; do 16; _=_ || $1 || $4; $1= $2; end; say _ || $3; return</lang>
- output:
(Code page 437 was used for the example below using DOS under Microsoft Windows.)
0 1 2 3 4 5 6 7 8 9 A B C D E F ╔═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╤═══╗ ║nul│soh│stx│etx│eot│enq│ack│bel│ bs│tab│ lf│ vt│ ff│ cr│ so│ si║ 0 ║ │ ☺ │ ☻ │ ♥ │ ♦ │ ♣ │ ♠ │═══│═══│═══│═══│ ♂ │ ♀ │═══│ ♫ │ ☼ ║ 0 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║dle│dc1│dc2│dc3│dc4│nak│syn│etb│can│ em│eof│esc│ fs│ gs│ rs│ us║ 1 ║ ► │ ◄ │ ↕ │ ‼ │ ¶ │ § │ ▬ │ ↨ │ ↑ │ ↓ │ → │ ← │ ∟ │ ↔ │ ▲ │ ▼ ║ 1 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 2 ║bla│ ! │ " │ # │ $ │ % │ & │ ' │ ( │ ) │ * │ + │ , │ - │ . │ / ║ 2 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 3 ║ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ : │ ; │ < │ = │ > │ ? ║ 3 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 4 ║ @ │ A │ B │ C │ D │ E │ F │ G │ H │ I │ J │ K │ L │ M │ N │ O ║ 4 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 5 ║ P │ Q │ R │ S │ T │ U │ V │ W │ X │ Y │ Z │ [ │ \ │ ] │ ^ │ _ ║ 5 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 6 ║ ` │ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ m │ n │ o ║ 6 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 7 ║ p │ q │ r │ s │ t │ u │ v │ w │ x │ y │ z │ { │ | │ } │ ~ │ ⌂ ║ 7 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 8 ║ Ç │ ü │ é │ â │ ä │ à │ å │ ç │ ê │ ë │ è │ ï │ î │ ì │ Ä │ Å ║ 8 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ 9 ║ É │ æ │ Æ │ ô │ ö │ ò │ û │ ù │ ÿ │ Ö │ Ü │ ¢ │ £ │ ¥ │ ₧ │ ƒ ║ 9 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ A ║ á │ í │ ó │ ú │ ñ │ Ñ │ ª │ º │ ¿ │ ⌐ │ ¬ │ ½ │ ¼ │ ¡ │ « │ » ║ A ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ B ║ ░ │ ▒ │ ▓ │ │ │ ┤ │ ╡ │ ╢ │ ╖ │ ╕ │ ╣ │ ║ │ ╗ │ ╝ │ ╜ │ ╛ │ ┐ ║ B ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ C ║ └ │ ┴ │ ┬ │ ├ │ ─ │ ┼ │ ╞ │ ╟ │ ╚ │ ╔ │ ╩ │ ╦ │ ╠ │ ═ │ ╬ │ ╧ ║ C ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ D ║ ╨ │ ╤ │ ╥ │ ╙ │ ╘ │ ╒ │ ╓ │ ╫ │ ╪ │ ┘ │ ┌ │ █ │ ▄ │ ▌ │ ▐ │ ▀ ║ D ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ E ║ α │ ß │ Γ │ π │ Σ │ σ │ µ │ τ │ Φ │ Θ │ Ω │ δ │ ∞ │ φ │ ε │ ∩ ║ E ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ F ║ ≡ │ ± │ ≥ │ ≤ │ ⌠ │ ⌡ │ ÷ │ ≈ │ ° │ ∙ │ · │ √ │ ⁿ │ ² │ ■ │ ║ F ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝ 0 1 2 3 4 5 6 7 8 9 A B C D E F
Ring
<lang ring>
- Project : Show Ascii table
load "guilib.ring" load "stdlib.ring"
decarr = newlist(16,6) ascarr = newlist(16,6)
new qapp
{ win1 = new qwidget() { setwindowtitle("Show Ascii table") setgeometry(100,100,800,600) for n = 1 to 16 for m = 1 to 6 decarr[n][m] = new qpushbutton(win1) { x = 150+m*60 y = 30 + n*30 ind = string((m-1)*16+n+31) setgeometry(x,y,30,30) settext(ind) } next next for n = 1 to 16 for m = 1 to 6 ascarr[n][m] = new qpushbutton(win1) { x = 180+m*60 y = 30 + n*30 ind = (m-1)*16+n+31 setgeometry(x,y,30,30) if ind = 32 settext("Spc") loop ok if ind = 127 settext("Del") loop ok settext(char(ind)) } next next show() } exec() }
</lang> Output:
zkl
<lang zkl>const width=9; println(" ",[0..width].pump(String,"%4d".fmt)); [30..127].pump("".println,T(Void.Read,width,False), // don't fail on short lines
fcn(a,b,c){ String("%3d: ".fmt(a), vm.arglist.pump(String,"toChar", // parameters (ints) to list to text T("replace","\x1e",""),T("replace","\x1f",""), // 30,31 T("replace"," ","spc"),T("replace","\x7f","del"), "%-4s".fmt) ) })</lang>
- Output:
0 1 2 3 4 5 6 7 8 9 30: spc ! " # $ % & ' 40: ( ) * + , - . / 0 1 50: 2 3 4 5 6 7 8 9 : ; 60: < = > ? @ A B C D E 70: F G H I J K L M N O 80: P Q R S T U V W X Y 90: Z [ \ ] ^ _ ` a b c 100: d e f g h i j k l m 110: n o p q r s t u v w 120: x y z { | } ~ del