Show ASCII table: Difference between revisions
Thundergnat (talk | contribs) m (Thundergnat moved page Show Ascii table to Show ASCII table: Follow normal task title capitalization policy) |
(→{{header|Free Pascal}}: Pascalify example [previous version was a _translation_ of Go example]) |
||
Line 1,456: | Line 1,456: | ||
=={{header|Free Pascal}}== |
=={{header|Free Pascal}}== |
||
<lang pascal>// The FPC (FreePascal compiler) discards the program header |
|||
{{trans|Go}} |
|||
// (except in ISO-compliant “compiler modes”). |
|||
program showAsciiTable(output); |
|||
const |
|||
<lang pascal>program ShowASCIITable; |
|||
columnsTotal = 6; |
|||
type |
|||
// https://rosettacode.org/wiki/Show_Ascii_table |
|||
// The hash indicates a char-data type. |
|||
asciiCharacter = #32..#127; |
|||
uses |
|||
asciiCharacters = set of asciiCharacter; |
|||
sysutils, strutils; |
|||
var |
var |
||
character: asciiCharacter; |
|||
i, j: Integer; |
|||
characters: asciiCharacters; |
|||
s: String; |
|||
column, line: integer; |
|||
begin |
begin |
||
// characters needs to be initialized, |
|||
i := 0; |
|||
// because the next `include` below |
|||
j := 0; |
|||
// will _read_ the value `characters`. |
|||
s := ''; |
|||
// Reading _unintialized_ values, however, |
|||
// is considered bad practice in Pascal. |
|||
for i := 0 to 15 do begin |
|||
characters := []; |
|||
// `div` denotes integer division in Pascal, |
|||
while j < 128 do begin |
|||
// that means the result will be an _integer_-value. |
|||
case j of |
|||
line := (ord(high(asciiCharacter)) - ord(low(asciiCharacter))) |
|||
32: s := 'Spc'; |
|||
div columnsTotal + 1; |
|||
127: s := 'Del'; |
|||
// Note: In Pascal for-loop limits are _inclusive_. |
|||
otherwise s := chr(j); |
|||
for column := 0 to columnsTotal do |
|||
end; |
|||
begin |
|||
write(format('%s : %s', [padLeft(IntToStr(j), 3), padRight(s, 5)])); |
|||
// This is equivalent to |
|||
Inc(j, 16); |
|||
// characters := characters + […]; |
|||
⚫ | |||
// i.e. the union of two sets. |
|||
writeln(' '); |
|||
include(characters, chr(ord(low(asciiCharacter)) + column * line)); |
|||
⚫ | |||
⚫ | |||
for line := line downto 1 do |
|||
begin |
|||
// the for..in..do statement is an Extended Pascal extension |
|||
for character in characters do |
|||
begin |
|||
// `:6` specifies minimum width of argument |
|||
// [only works for write/writeLn/writeStr] |
|||
write(ord(character):6, ' : ', character); |
|||
⚫ | |||
// emit proper newline character on `output` |
|||
writeLn; |
|||
// `characters` is evaluated prior entering the loop, |
|||
// not every time an iteration finished. |
|||
for character in characters do |
|||
begin |
|||
// These statements are equivalent to |
|||
// characters := characters + [character]; |
|||
// characters := characters - [succ(character)]; |
|||
// respectively, but shorter to write, |
|||
// i.e. less susceptible to spelling mistakes. |
|||
exclude(characters, character); |
|||
include(characters, succ(character)); |
|||
end; |
|||
end; |
|||
end.</lang> |
end.</lang> |
||
{{out}} |
{{out}} |
||
<pre> 32 : |
<pre> 32 : 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 :</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
Revision as of 21:14, 7 November 2020
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Show ASCII character set from values 32 to 127 (decimal) in a table format.
6502 Assembly
<lang asm>==========================================================================
- task
- show ascii table
- language
- 6502 Assembly
- for
- : rosettacode.org
- run
- on a Commodore 64 with command
- sys 49152
- same logic of "Commodore BASIC"
- assembler win2c64 by Aart Bik
- http://www.aartbik.com/
- 2020-05-01 alvalongo
- ==========================================================================
- constants
cr = 13 ; carriage-return white = 5 ; color white
- ----------------------------------------------
- memory on zero page
linnum = $14
- ----------------------------------------------
- kernel routines
linstr = $bdcd ; C64 ROM : convert a 16-bit value to string and print on current device (default screen) chrout = $ffd2 ; C64 ROM kernel: output a character to current device, default screen ; use $fded for Apple 2
- ----------------------------------------------
.org $c000 ; start at free RAM, on Commodore 64
- ----------------------------------------------
l100 lda #147 ; clear screen
jsr chrout ;
l110 lda #14 ;character set 2, upper/lower case mode
jsr chrout ; lda #white ; color for characters jsr chrout ;
l120 lda #<msg1
ldx #>msg1 jsr prtmsg ;
l130 lda #<msg2
ldx #>msg2 jsr prtmsg ;
l140 lda #cr
jsr chrout ;
l150 lda #0
sta row ;
l160 lda #0
sta column ;
l170 clc
lda row adc #32 sta ascii lda column asl ; times 2, 2 asl ; times 2, 4 asl ; times 2, 8 asl ; times 2, 16 adc ascii sta ascii ;
l180 cmp #100
bcs l185 ; equal or greater than lda #" " ; a space before values less than 100 jsr chrout ;
l185 ldx ascii
lda #0 jsr linstr ; convert to string and print on screen lda #":" jsr chrout lda ascii jsr chrout lda #" " jsr chrout ;
l190 inc column ; next column
lda column cmp #5 bcc l170 beq l170 ;
l200 lda #cr
jsr chrout ;
l210 inc row ; next row
lda row cmp #15 bcc l160 beq l160 ;
l220 rts ; return to operating system
- ----------------------------------------------
- print message
prtmsg sta linnum
stx linnum+1 ldy #0
l310 lda (linnum),y
beq l320 jsr chrout iny bne l310
l320 lda #cr
jsr chrout rts
- ----------------------------------------------
msg1 .byte "COMMODORE 64 - BASIC V2",0 msg2 .byte "CHARACTER SET 2 UPPER/LOWER CASE MODE",0 row .byte 0 column .byte 0 ascii .byte 0 </lang>
8080 Assembly
<lang 8080asm> org 100h mvi a,32 ; Start with space mvi d,16 ; 16 lines dochar: mov c,a ; Print number call putnum mov a,c lxi h,spc ; Is it space? cpi 32 jz print lxi h,del cpi 127 ; Is it del? jz print lxi h,chr ; Character mov m,a print: call puts adi 16 ; Next column jp dochar ; Done with this line? lxi h,nl call puts sui 95 ; Next line dcr d jnz dochar ret ;;; Print number in A. C, D preserved. putnum: lxi h,num ; Set number string to spaces push h mvi b,' ' mov m,b inx h mov m,b inx h mov m,b dgts: mvi b,-1 divmod: sui 10 ; B = A/10, A = (A mod 10)-10 inr b jnc divmod adi 58 ; Make digit mov m,a ; Store digit dcx h mov a,b ; Next digit ana a jnz dgts pop h ; Print number ;;; Print zero-terminated (...ish) string puts: mov e,m call putch inx h dcr e jp puts ret ;;; Output character in E using CP/M call, ;;; preserving registers putch: push psw push b push d push h mvi c,2 call 5 pop h pop d pop b pop psw ret nl: db 13,10,0 ; Newline num: db ' : ',0 ; Placeholder for number string spc: db 'Spc ',0 ; Space del: db 'Del ',0 ; Del chr: db '* ',0 ; Placeholder for character</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
8086 Assembly
<lang asm> cpu 8086 bits 16 putch: equ 2h section .text org 100h mov cx,16 ; 16 lines mov bh,32 ; Start at 32 dochar: mov al,bh ; Print number call putnum cmp bh,32 ; Space? je .spc cmp bh,127 ; Del? je .del mov [chr],bh ; Otherwise, print character mov di,chr jmp .out .spc: mov di,spc jmp .out .del: mov di,del .out: call putstr add bh,16 ; Next column cmp bh,128 ; Done with this line? jb dochar mov di,nl ; Print newline call putstr sub bh,95 ; Do next line loop dochar ret ;;; Print number in AL as ASCII, right-aligned in 3 characters putnum: mov dx,2020h ; Put spaces in number mov di,num ; Two spaces mov [di],dx inc di inc di mov [di],dh ; Third space mov bl,10 ; Divisor .div: xor ah,ah ; Write digits div bl add ah,'0' mov [di],ah dec di test al,al jnz .div mov di,num ; Print number putstr: mov ah,putch ; Use zero-terminated strings .loop: mov dl,[di] test dl,dl jz .done int 21h inc di jmp .loop .done: ret section .data num: db ' : ',0 ; Placeholder for number string nl: db 13,10,0 ; Newline spc: db 'Spc ',0 ; Space del: db 'Del ',0 ; Del chr: db '* ',0 ; Placeholder for character</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
Ada
<lang ada>with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Ascii_Table is
N : Integer;
begin
for R in 0 .. 15 loop for C in 0 .. 5 loop N := 32 + 16 * C + R; Put (N, 3); Put (" : "); case N is when 32 => Put ("Spc "); when 127 => Put ("Del "); when others => Put (Character'Val (N) & " "); end case; end loop; New_Line; end loop;
end Ascii_Table;</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
ALGOL 68
<lang algol68>BEGIN
# generate an ascii table for characters 32 - 127 # INT char count := 1; FOR c FROM 32 TO 127 DO print( ( whole( c, -4 ) , ": " , IF c = 32 THEN "SPC" ELIF c = 127 THEN "DEL" ELSE " " + REPR c + " " FI ) ); IF char count = 0 THEN print( ( newline ) ) FI; ( char count PLUSAB 1 ) MODAB 6 OD
END</lang>
- Output:
32: SPC 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
ALGOL W
<lang algolw>begin
% generate an ascii table for chars 32 - 127 % integer cPos; cPos := 0; for i := 32 until 127 do begin if cPos = 0 then write(); cPos := ( cPos + 1 ) rem 6; writeon( i_w := 3, s_w := 0, i, ": " ); if i = 32 then writeon( "Spc ") else if i = 127 then writeon( "Del " ) else writeon( code( i ), " " ) end for_i
end.</lang>
- Output:
32: Spc 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
APL
<lang APL>{(¯3↑⍕⍵),': ',∊('Spc' 'Del'(⎕UCS ⍵))[32 127⍳⍵]}¨⍉6 16⍴31+⍳96</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
AppleScript
<lang applescript>-- asciiTable :: () -> String on asciiTable()
script row on |λ|(x) concat(map(justifyLeft(12, space), x)) end |λ| end script unlines(map(row, ¬ transpose(chunksOf(16, map(my asciiEntry, ¬ enumFromTo(32, 127))))))
end asciiTable
TEST ---------------------------
on run
asciiTable()
end run
DISPLAY -------------------------
-- 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 {} ≠ a then {a} & go(|2| of ab) else a end if end go end script result's go(xs)
end chunksOf
-- 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
-- justifyLeft :: Int -> Char -> String -> String
on justifyLeft(n, cFiller)
script on |λ|(strText) if n > length of strText then text 1 thru n of (strText & replicate(n, cFiller)) else strText end if end |λ| end script
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|
-- 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
-- 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
-- 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
-- Tuple (,) :: a -> b -> (a, b)
on Tuple(a, b)
{type:"Tuple", |1|:a, |2|:b, length:2}
end Tuple
-- Simplified version - assuming rows of unvarying length.
-- transpose :: a -> a
on transpose(rows)
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
-- 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
AutoHotKey
<lang AutoHotKey>AutoTrim,Off ;Allows for whitespace at end of variable to separate converted characters
MessageText := ;The text to display in the final message box. CurrentASCII := 32 ;Current ASCII number to convert and add to MessageText ConvertedCharacter := ;Stores the currently converted ASCII code RowLength := 0 ;Keeps track of the number of converted ASCII numbers in each row
Loop { ;Loops through each ASCII character and makes a list in MessageText if CurrentASCII > 127 ;When the current ASCII number goes over 127, terminate the loop Break if (RowLength = 6) { ;Checks if the row is 6 converted characters long, and if so, inserts a line break (`n) MessageText = %MessageText%`n RowLength := 0 } if (CurrentASCII = 32) { ConvertedCharacter = SPC } else { if (CurrentASCII = 127) { ConvertedCharacter = DEL } else { ConvertedCharacter := Chr(CurrentASCII) ;Converts CurrentASCII number using Chr() and stores it in ConvertedCharacter } } MessageText = %MessageText%%CurrentASCII%: %ConvertedCharacter%`t ;Adds converted ASCII to end of MessageText CurrentASCII := CurrentASCII + 1 RowLength := RowLength + 1 } MsgBox, % MessageText ;Displays a message box with the ASCII conversion table, from the MessageText variable return</lang>
- Output:
32: SPC 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
AWK
<lang AWK># syntax: GAWK -f SHOW_ASCII_TABLE.AWK
- syntax: MAWK -f SHOW_ASCII_TABLE.AWK
BEGIN {
n00_15 = "NUL,SOH,STX,ETX,EOT,ENQ,ACK,BEL,BS,HT,LF,VT,FF,CR,SO,SI" n16_31 = "DLE,DC1,DC2,DC3,DC4,NAK,SYN,ETB,CAN,EM,SUB,ESC,FS,GS,RS,US" split(n00_15 "," n16_31,arr,",") for (i=0; i<16; i++) { for (j=0+i; j<128; j+=16) { if (j <= 31) { x = arr[j+1] continue # don't show values 0 - 31 } else if (j == 32) { x = "SP" } else if (j == 127) { x = "DEL" } else { x = sprintf("%c",j) } printf("%3d: %-5s",j,x) } printf("\n") } exit(0)
}</lang>
- Output:
32: SP 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
C++
<lang c++>
- include <string>
- include <iomanip>
- include <iostream>
- define HEIGHT 16
- define WIDTH 6
- define ASCII_START 32
- define ASCII_END 128
// ASCII special characters
- define SPACE 32
- define DELETE 127
std::string displayAscii(int ascii) {
switch(ascii) { case SPACE: return "Spc"; case DELETE: return "Del"; default: return std::string(1,char(ascii)); }
}
int main(void) {
for(int row = 0; row < HEIGHT; ++row) { for(int col = 0; col < WIDTH; ++col) { int ascii = ASCII_START + row + col*HEIGHT; std::cout << std::right << std::setw(3) << ascii << " : " \ << std::left << std::setw(6) << displayAscii(ascii); } std::cout << std::endl; }
} </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 csharp>using static System.Console; using static System.Linq.Enumerable;
public class Program {
static void Main() { for (int start = 32; start + 16 * 5 < 128; start++) { WriteLine(string.Concat(Range(0, 6).Select(i => $"{start+16*i, 3} : {Text(start+16*i), -6}"))); }
string Text(int index) => index == 32 ? "Sp" : index == 127 ? "Del" : (char)index + ""; }
}</lang>
- Output:
32 : Sp 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
Caché ObjectScript
<lang Caché ObjectScript>SHOWASCII
; this is 96 characters, so do 6 columns of 16 for i = 32:1:127 { ; get remainder when div by 6, sort columns by remainder 2 3 4 5 0 1 set rem = i # 6 if rem = 2 { write ! }
; spacing (tabs) set x = $case(rem,2:0,3:8,4:16,5:24,0:32,:40)
; char to write set wrtchr = $case(i,32:"Spc",127:"Del",:$char(i)) write ?x,$justify(i,3)_": "_wrtchr }
quit</lang>
- Output:
SAMPLES>do ^SHOWASCII 32: Spc 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
Clojure
The first code shown is flexible enough to lay the grid out in any number of columns that divides evenly into the number of ASCII codes to be displayed.
Further down, the code will be modified to handle the more general case of a grid where the number of codes to be displayed doesn't match the product of the numbers of rows and columns in the desired grid. That case is made a little trickier by the desire to print the table in "column-major order", which seems the friendlier to the end-user reading the table. <lang Clojure> (defn cell [code]
(let [text (get {32 "Spc", 127 "Del"} code (char code))] (format "%3d: %3s" code text)))
(defn ascii-table [n-cols st-code end-code]
(let [n-cells (inc (- end-code st-code)) n-rows (/ n-cells n-cols) code (fn [r c] (+ st-code r (* c n-rows))) row-str (fn [r] (clojure.string/join " " (map #(cell (code r %)) (range n-cols))))] (->> (for [r (range n-rows)] (row-str r)) (clojure.string/join "\n"))))
(defn pr-ascii-table [n-cols st-code end-code]
(println (ascii-table n-cols st-code end-code)))
</lang>
- Output:
(pr-ascii-table 6 32 127) 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 (pr-ascii-table 8 32 127) 32: Spc 44: , 56: 8 68: D 80: P 92: \ 104: h 116: t 33: ! 45: - 57: 9 69: E 81: Q 93: ] 105: i 117: u 34: " 46: . 58: : 70: F 82: R 94: ^ 106: j 118: v 35: # 47: / 59: ; 71: G 83: S 95: _ 107: k 119: w 36: $ 48: 0 60: < 72: H 84: T 96: ` 108: l 120: x 37: % 49: 1 61: = 73: I 85: U 97: a 109: m 121: y 38: & 50: 2 62: > 74: J 86: V 98: b 110: n 122: z 39: ' 51: 3 63: ? 75: K 87: W 99: c 111: o 123: { 40: ( 52: 4 64: @ 76: L 88: X 100: d 112: p 124: | 41: ) 53: 5 65: A 77: M 89: Y 101: e 113: q 125: } 42: * 54: 6 66: B 78: N 90: Z 102: f 114: r 126: ~ 43: + 55: 7 67: C 79: O 91: [ 103: g 115: s 127: Del
Now, if we want to handle the more general case of being able to print tables where the number of columns creates a final column that is shorter than the others, the code needs to be a little more complicated. But the amount of change needed isn't really that large.
For readers new to Clojure, the calculation of "n-rows" has a couple points to note. First, this makes use of the (fairly seamless) Java-interop capability, using the "ceil" function in Java's Math class. Secondly, Clojure has a "ratio" data type that Java doesn't understand, so we coerce the input to the Java function into a floating-point value by adding 1.0 into the list of divisors.
There are 2 output examples, the first simply creates a grid with an incomplete final column. The second case additionally demonstrates the ability to modify the range of ASCII codes displayed.
<lang Clojure> (defn cell [code]
(if (nil? code) "" (let [text (get {32 "Spc", 127 "Del"} code (char code))] (format "%3d: %3s" code text))))
(defn ascii-table [n-cols st-code end-code]
(let [n-cells (inc (- end-code st-code)) n-rows (int (Math/ceil (/ n-cells n-cols 1.0))) code (fn [r c] (let [cd (+ st-code r (* c n-rows))] (if (> cd end-code) nil cd))) row-str (fn [r] (clojure.string/join " " (map #(cell (code r %)) (range n-cols))))] (->> (for [r (range n-rows)] (row-str r)) (clojure.string/join "\n"))))
(defn pr-ascii-table [n-cols st-code end-code]
(println (ascii-table n-cols st-code end-code)))
</lang>
- Output:
(pr-ascii-table 7 32 127) 32: Spc 46: . 60: < 74: J 88: X 102: f 116: t 33: ! 47: / 61: = 75: K 89: Y 103: g 117: u 34: " 48: 0 62: > 76: L 90: Z 104: h 118: v 35: # 49: 1 63: ? 77: M 91: [ 105: i 119: w 36: $ 50: 2 64: @ 78: N 92: \ 106: j 120: x 37: % 51: 3 65: A 79: O 93: ] 107: k 121: y 38: & 52: 4 66: B 80: P 94: ^ 108: l 122: z 39: ' 53: 5 67: C 81: Q 95: _ 109: m 123: { 40: ( 54: 6 68: D 82: R 96: ` 110: n 124: | 41: ) 55: 7 69: E 83: S 97: a 111: o 125: } 42: * 56: 8 70: F 84: T 98: b 112: p 126: ~ 43: + 57: 9 71: G 85: U 99: c 113: q 127: Del 44: , 58: : 72: H 86: V 100: d 114: r 45: - 59: ; 73: I 87: W 101: e 115: s (pr-ascii-table 7 36 120) 36: $ 49: 1 62: > 75: K 88: X 101: e 114: r 37: % 50: 2 63: ? 76: L 89: Y 102: f 115: s 38: & 51: 3 64: @ 77: M 90: Z 103: g 116: t 39: ' 52: 4 65: A 78: N 91: [ 104: h 117: u 40: ( 53: 5 66: B 79: O 92: \ 105: i 118: v 41: ) 54: 6 67: C 80: P 93: ] 106: j 119: w 42: * 55: 7 68: D 81: Q 94: ^ 107: k 120: x 43: + 56: 8 69: E 82: R 95: _ 108: l 44: , 57: 9 70: F 83: S 96: ` 109: m 45: - 58: : 71: G 84: T 97: a 110: n 46: . 59: ; 72: H 85: U 98: b 111: o 47: / 60: < 73: I 86: V 99: c 112: p 48: 0 61: = 74: J 87: W 100: d 113: q
Commodore BASIC
<lang qbasic>100 PRINT CHR$(147);:REM CLEAR SCREEN 110 PRINT CHR$(14);:REM CHARACTER SET 2 120 PRINT "COMMODORE 64 - BASIC V2" 130 PRINT "CHARACTER SET 2" 140 PRINT 150 FOR R=0 TO 15 160 FOR C=0 TO 5 170 A=32+R+C*16 180 PRINT RIGHT$(" "+STR$(A),4);":";CHR$(A); 190 NEXT C 200 PRINT 210 NEXT R </lang>
- Output:
Common Lisp
<lang lisp>(setq startVal 32) (setq endVal 127) (setq cols 6)
(defun print-val (val) "Prints the value for that ascii number" (cond ((= val 32) (format t " 32: SPC ")) ((= val 127) (format t "127: DEL~%")) ((and (zerop (mod (- val startVal) cols)) (< val 100)) (format t "~% ~d: ~a " val (int-char val))) ((and (zerop (mod (- val startVal) cols)) (>= val 100)) (format t "~%~d: ~a " val (int-char val))) ((< val 100) (format t " ~d: ~a " val (int-char val))) ((>= val 100) (format t "~d: ~a " val (int-char val))) (t nil)))
(defun get-range (lower upper) "Returns a list of range lower to upper"
(if (> lower upper) '() (cons lower (get-range (+ 1 lower) upper))))
(mapcar #'print-val (get-range startVal endVal))</lang>
- Output:
32: SPC 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
Dc
<lang dc>[ [1q]S.[>.0]xs.L. ] sl ## l: islt
- for initcode condcode incrcode body
- [1] [2] [3] [4]
[ [q]S. 4:. 3:. 2:. 1:. 1;.x [2;.x 0=. 4;.x 3;.x 0;.x]d0:.x Os.L.o ] sf
- f: for
- for( i=0 ; i<16 ; ++i ) {
- for( j=32+i ; j<128 ; j+=16 ) {
- pr "%3d", j, " : "
- ok = 0;
- if( j == 32 ) { pr "Spc"; ok=1; }
- if( j == 127 ) { pr "Del"; ok=1; }
- if( !ok ) { pr "%c ", j; }
- pr " "
- }
- pr NL
- }
[0si] [li 16 llx] [li1+si] [
[32 li+ sj] [lj 128 llx] [lj 16+ sj] [ [[ ]P]sT 100 lj <T 10 lj <T ljn [ : ]P 0so [[Spc]P 1so]sT lj 32 =T [[Del]P 1so]sT lj 127 =T [ljP [ ]P ]sT lo 0 =T [ ]P ] lfx []pP
] lfx</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
Delphi
<lang Delphi> program Show_Ascii_table;
{$APPTYPE CONSOLE}
var
i, j: Integer; k: string;
begin
for i := 0 to 15 do begin j := 32 + i; while j < 128 do begin case j of 32: k := 'Spc'; 127: k := 'Del'; else k := chr(j); end; Write(j: 3, ' : ', k: 3, ' '); inc(j, 16); end; Writeln; end; Readln;
end.
</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
Forth
Idiomatic Forth version is factored differently than conventional languages, allowing each factor to be tested independently at the console, bottom up. <lang forth>DECIMAL
- ###: ( c -- ) 3 .R ." : " ;
- .CHAR ( c -- )
DUP CASE BL OF ###: ." spc" ENDOF 127 OF ###: ." del" ENDOF DUP ###: EMIT 2 SPACES ENDCASE 3 SPACES ;
- .ROW ( n2 n1 -- )
CR DO I .CHAR 16 +LOOP ;
- ASCII.TABLE ( -- )
16 0 DO 113 I + 32 I + .ROW LOOP ;</lang>
Test Output at the console <lang forth>ASCII.TABLE
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 ok</lang>
Fortran
The dollar sign $ in the format string isn't part of the standard but is a common extension. ACHAR may not be part of the standard, either. <lang Fortran> PROGRAM ASCTBL ! show the ASCII characters from 32-127
IMPLICIT NONE INTEGER I, J CHARACTER*3 H
10 FORMAT (I3, ':', A3, ' ', $) 20 FORMAT () DO J = 0, 15, +1 DO I = 32+J, 127, +16 IF (I > 32 .AND. I < 127) THEN H = ' ' // ACHAR(I) // ' ' ELSE IF (I .EQ. 32) THEN H = 'Spc' ELSE IF (I .EQ. 127) THEN H = 'Del' ELSE STOP 'bad value of i' END IF PRINT 10, I, H END DO PRINT 20 END DO
END
</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
FreeBASIC
<lang freebasic>function getasc( n as unsigned byte ) as string
if n=32 then return "Spc" if n=127 then return "Del" return chr(n)+" "
end function
function padto( i as ubyte, j as integer ) as string
return wspace(i-len(str(j)))+str(j)
end function
dim as unsigned byte r, c, n dim as string disp
for r = 0 to 15
disp = "" for c = 0 to 5 n = 32 + 6*r + c disp = disp + padto(3, n) + ": " + getasc(n) + " " next c print disp
next r </lang>
- Output:
32: Spc 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
Free Pascal
<lang pascal>// The FPC (FreePascal compiler) discards the program header // (except in ISO-compliant “compiler modes”). program showAsciiTable(output);
const columnsTotal = 6;
type // The hash indicates a char-data type. asciiCharacter = #32..#127; asciiCharacters = set of asciiCharacter;
var character: asciiCharacter; characters: asciiCharacters; column, line: integer; begin // characters needs to be initialized, // because the next `include` below // will _read_ the value `characters`. // Reading _unintialized_ values, however, // is considered bad practice in Pascal. characters := []; // `div` denotes integer division in Pascal, // that means the result will be an _integer_-value. line := (ord(high(asciiCharacter)) - ord(low(asciiCharacter))) div columnsTotal + 1; // Note: In Pascal for-loop limits are _inclusive_. for column := 0 to columnsTotal do begin // This is equivalent to // characters := characters + […]; // i.e. the union of two sets. include(characters, chr(ord(low(asciiCharacter)) + column * line)); end;
for line := line downto 1 do begin // the for..in..do statement is an Extended Pascal extension for character in characters do begin // `:6` specifies minimum width of argument // [only works for write/writeLn/writeStr] write(ord(character):6, ' : ', character); end; // emit proper newline character on `output` writeLn;
// `characters` is evaluated prior entering the loop, // not every time an iteration finished. for character in characters do begin // These statements are equivalent to // characters := characters + [character]; // characters := characters - [succ(character)]; // respectively, but shorter to write, // i.e. less susceptible to spelling mistakes. exclude(characters, character); include(characters, succ(character)); end; end; end.</lang>
- Output:
32 : 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 :
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
asciiEntry :: Int -> String asciiEntry n =
let k = asciiName n in case k of [] -> k _ -> concat [justifyRight 4 ' ' (show n), " : ", k]
asciiName :: Int -> String asciiName n
| 32 > n = [] | 127 < n = [] | 32 == n = "Spc" | 127 == n = "Del" | otherwise = [chr n]
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
IS-BASIC
<lang IS-BASIC>100 TEXT 80 110 FOR R=0 TO 15 120 FOR C=32+R TO 112+R STEP 16 130 PRINT USING "###":C;:PRINT ": ";CHR$(C), 140 NEXT 150 PRINT 160 NEXT</lang>
J
a. is the 256 ASCII character set. We'll do a bit of work to make it pretty as the other examples.
32}._129}.a. !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ NB. A are the decimal ASCII values [A =: 10 |."1 ] 12 ": |: _16 [\ 32 }. i. 128 32 48 64 80 96 112 33 49 65 81 97 113 34 50 66 82 98 114 35 51 67 83 99 115 36 52 68 84 100 116 37 53 69 85 101 117 38 54 70 86 102 118 39 55 71 87 103 119 40 56 72 88 104 120 41 57 73 89 105 121 42 58 74 90 106 122 43 59 75 91 107 123 44 60 76 92 108 124 45 61 77 93 109 125 46 62 78 94 110 126 47 63 79 95 111 127 NB. B are the corresponding ASCII characters [B =: |:_16[\32}._128}.a. 0@P`p !1AQaq "2BRbr #3CScs $4DTdt %5EUeu &6FVfv '7GWgw (8HXhx )9IYiy *:JZjz +;K[k{ ,<L\l| -=M]m} .>N^n~ /?O_o� NB. stuff the characters into the text array of numbers B [`((4 12 p. i. 6)"_)`]}"1 A 32 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 �
Java
<lang java> public class ShowAsciiTable {
public static void main(String[] args) { for ( int i = 32 ; i <= 127 ; i++ ) { if ( i == 32 || i == 127 ) { String s = i == 32 ? "Spc" : "Del"; System.out.printf("%3d: %s ", i, s); } else { System.out.printf("%3d: %c ", i, i); } if ( (i-1) % 6 == 0 ) { System.out.println(); } } }
} </lang>
- Output:
32: Spc 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
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
Jsish
<lang javascript>#!/usr/bin/env jsish
/* Show ASCII table, -showAll true to include control codes */ function showASCIITable(args:array|string=void, conf:object=void) {
var options = { // Rosetta Code, Show ASCII table rootdir :, // Root directory. showAll : false // include control code labels if true }; var self = {}; parseOpts(self, options, conf);
function main() { var e; var first = (self.showAll) ? 0 : 2; var filler = '='.repeat(19 + ((first) ? 0 : 9)); puts(filler, "ASCII table", filler + '='); var labels = [ 'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS ', 'HT ', 'LF ', 'VT ', 'FF ', 'CR ', 'SO ', 'SI ', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM ', 'SUB', 'ESC', 'FS ', 'GS ', 'RS ', 'US ']; var table = new Array(128); for (e = 0; e < 32; e++) table[e] = labels[e]; for (e = 32; e < 127; e++) table[e] = ' ' + Util.fromCharCode(e) + ' '; table[32] = 'SPC'; table[127] = 'DEL';
for (var row = 0; row < 16; row++) { for (var col = first; col < 8; col++) { e = row + col * 16; printf('%03d %s ', e, table[e]); } printf('\n'); } } return main();
}
provide(showASCIITable, 1);
if (isMain()) {
if (Interp.conf('unitTest')) showASCIITable(, {showAll:true}); else runModule(showASCIITable);
}
/*
!EXPECTSTART!
====================== ASCII table =======================
000 NUL 016 DLE 032 SPC 048 0 064 @ 080 P 096 ` 112 p 001 SOH 017 DC1 033 ! 049 1 065 A 081 Q 097 a 113 q 002 STX 018 DC2 034 " 050 2 066 B 082 R 098 b 114 r 003 ETX 019 DC3 035 # 051 3 067 C 083 S 099 c 115 s 004 EOT 020 DC4 036 $ 052 4 068 D 084 T 100 d 116 t 005 ENQ 021 NAK 037 % 053 5 069 E 085 U 101 e 117 u 006 ACK 022 SYN 038 & 054 6 070 F 086 V 102 f 118 v 007 BEL 023 ETB 039 ' 055 7 071 G 087 W 103 g 119 w 008 BS 024 CAN 040 ( 056 8 072 H 088 X 104 h 120 x 009 HT 025 EM 041 ) 057 9 073 I 089 Y 105 i 121 y 010 LF 026 SUB 042 * 058 : 074 J 090 Z 106 j 122 z 011 VT 027 ESC 043 + 059 ; 075 K 091 [ 107 k 123 { 012 FF 028 FS 044 , 060 < 076 L 092 \ 108 l 124 | 013 CR 029 GS 045 - 061 = 077 M 093 ] 109 m 125 } 014 SO 030 RS 046 . 062 > 078 N 094 ^ 110 n 126 ~ 015 SI 031 US 047 / 063 ? 079 O 095 _ 111 o 127 DEL
!EXPECTEND!
- /</lang>
- Output:
prompt$ jsish -u showASCIITable.jsi [PASS] showASCIITable.jsi prompt$ ./showASCIITable.jsi =================== ASCII table ==================== 032 SPC 048 0 064 @ 080 P 096 ` 112 p 033 ! 049 1 065 A 081 Q 097 a 113 q 034 " 050 2 066 B 082 R 098 b 114 r 035 # 051 3 067 C 083 S 099 c 115 s 036 $ 052 4 068 D 084 T 100 d 116 t 037 % 053 5 069 E 085 U 101 e 117 u 038 & 054 6 070 F 086 V 102 f 118 v 039 ' 055 7 071 G 087 W 103 g 119 w 040 ( 056 8 072 H 088 X 104 h 120 x 041 ) 057 9 073 I 089 Y 105 i 121 y 042 * 058 : 074 J 090 Z 106 j 122 z 043 + 059 ; 075 K 091 [ 107 k 123 { 044 , 060 < 076 L 092 \ 108 l 124 | 045 - 061 = 077 M 093 ] 109 m 125 } 046 . 062 > 078 N 094 ^ 110 n 126 ~ 047 / 063 ? 079 O 095 _ 111 o 127 DEL
Julia
Base Task
<lang julia>for i in 32:127
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" : i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|" print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c") (i&7)==7 ? println() : print(" ")
end</lang>
- Output:
32 20 | | 33 21 |!| 34 22 |"| 35 23 |#| 36 24 |$| 37 25 |%| 38 26 |&| 39 27 |'| 40 28 |(| 41 29 |)| 42 2a |*| 43 2b |+| 44 2c |,| 45 2d |-| 46 2e |.| 47 2f |/| 48 30 |0| 49 31 |1| 50 32 |2| 51 33 |3| 52 34 |4| 53 35 |5| 54 36 |6| 55 37 |7| 56 38 |8| 57 39 |9| 58 3a |:| 59 3b |;| 60 3c |<| 61 3d |=| 62 3e |>| 63 3f |?| 64 40 |@| 65 41 |A| 66 42 |B| 67 43 |C| 68 44 |D| 69 45 |E| 70 46 |F| 71 47 |G| 72 48 |H| 73 49 |I| 74 4a |J| 75 4b |K| 76 4c |L| 77 4d |M| 78 4e |N| 79 4f |O| 80 50 |P| 81 51 |Q| 82 52 |R| 83 53 |S| 84 54 |T| 85 55 |U| 86 56 |V| 87 57 |W| 88 58 |X| 89 59 |Y| 90 5a |Z| 91 5b |[| 92 5c |\| 93 5d |]| 94 5e |^| 95 5f |_| 96 60 |`| 97 61 |a| 98 62 |b| 99 63 |c| 100 64 |d| 101 65 |e| 102 66 |f| 103 67 |g| 104 68 |h| 105 69 |i| 106 6a |j| 107 6b |k| 108 6c |l| 109 6d |m| 110 6e |n| 111 6f |o| 112 70 |p| 113 71 |q| 114 72 |r| 115 73 |s| 116 74 |t| 117 75 |u| 118 76 |v| 119 77 |w| 120 78 |x| 121 79 |y| 122 7a |z| 123 7b |{| 124 7c ||| 125 7d |}| 126 7e |~| 127 7f |�|
Extended Ascii
The appearance of the table with the extended ASCII characters below depends on the font (code page) used in the terminal and in your browser (DejaVu Sans Mono is a reasonable choice). The output shown is copied from the console ConEmu in Windows 10.
<lang julia>for i in 0:255
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" : i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|" print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c") (i&7)==7 ? println() : print(" ")
end</lang>
- Output:
0 00 NUL 1 01 |☺| 2 02 |☻| 3 03 |♥| 4 04 |♦| 5 05 |♣| 6 06 |♠| 7 07 BEL 8 08 BKS 9 09 TAB 10 0a LF 11 0b |♂| 12 0c |♀| 13 0d CR 14 0e |♫| 15 0f |☼| 16 10 |►| 17 11 |◄| 18 12 |↕| 19 13 |‼| 20 14 |¶| 21 15 |§| 22 16 |■| 23 17 |↨| 24 18 |↑| 25 19 |↓| 26 1a |→| 27 1b ESC 28 1c |∟| 29 1d |↔| 30 1e |▲| 31 1f |▼| 32 20 | | 33 21 |!| 34 22 |"| 35 23 |#| 36 24 |$| 37 25 |%| 38 26 |&| 39 27 |'| 40 28 |(| 41 29 |)| 42 2a |*| 43 2b |+| 44 2c |,| 45 2d |-| 46 2e |.| 47 2f |/| 48 30 |0| 49 31 |1| 50 32 |2| 51 33 |3| 52 34 |4| 53 35 |5| 54 36 |6| 55 37 |7| 56 38 |8| 57 39 |9| 58 3a |:| 59 3b |;| 60 3c |<| 61 3d |=| 62 3e |>| 63 3f |?| 64 40 |@| 65 41 |A| 66 42 |B| 67 43 |C| 68 44 |D| 69 45 |E| 70 46 |F| 71 47 |G| 72 48 |H| 73 49 |I| 74 4a |J| 75 4b |K| 76 4c |L| 77 4d |M| 78 4e |N| 79 4f |O| 80 50 |P| 81 51 |Q| 82 52 |R| 83 53 |S| 84 54 |T| 85 55 |U| 86 56 |V| 87 57 |W| 88 58 |X| 89 59 |Y| 90 5a |Z| 91 5b |[| 92 5c |\| 93 5d |]| 94 5e |^| 95 5f |_| 96 60 |`| 97 61 |a| 98 62 |b| 99 63 |c| 100 64 |d| 101 65 |e| 102 66 |f| 103 67 |g| 104 68 |h| 105 69 |i| 106 6a |j| 107 6b |k| 108 6c |l| 109 6d |m| 110 6e |n| 111 6f |o| 112 70 |p| 113 71 |q| 114 72 |r| 115 73 |s| 116 74 |t| 117 75 |u| 118 76 |v| 119 77 |w| 120 78 |x| 121 79 |y| 122 7a |z| 123 7b |{| 124 7c ||| 125 7d |}| 126 7e |~| 127 7f |�| 128 80 |�| 129 81 |�| 130 82 |�| 131 83 |�| 132 84 |�| 133 85 |�| 134 86 |�| 135 87 |�| 136 88 |�| 137 89 |�| 138 8a |�| 139 8b |�| 140 8c |�| 141 8d |�| 142 8e |�| 143 8f |�| 144 90 |�| 145 91 |�| 146 92 |�| 147 93 |�| 148 94 |�| 149 95 |�| 150 96 |�| 151 97 |�| 152 98 |�| 153 99 |�| 154 9a |�| 155 9b CSI 156 9c |�| 157 9d |�| 158 9e |�| 159 9f |�| 160 a0 | | 161 a1 |¡| 162 a2 |¢| 163 a3 |£| 164 a4 |¤| 165 a5 |¥| 166 a6 |¦| 167 a7 |§| 168 a8 |¨| 169 a9 |©| 170 aa |ª| 171 ab |«| 172 ac |¬| 173 ad | | 174 ae |®| 175 af |¯| 176 b0 |°| 177 b1 |±| 178 b2 |²| 179 b3 |³| 180 b4 |´| 181 b5 |µ| 182 b6 |¶| 183 b7 |·| 184 b8 |¸| 185 b9 |¹| 186 ba |º| 187 bb |»| 188 bc |¼| 189 bd |½| 190 be |¾| 191 bf |¿| 192 c0 |À| 193 c1 |Á| 194 c2 |Â| 195 c3 |Ã| 196 c4 |Ä| 197 c5 |Å| 198 c6 |Æ| 199 c7 |Ç| 200 c8 |È| 201 c9 |É| 202 ca |Ê| 203 cb |Ë| 204 cc |Ì| 205 cd |Í| 206 ce |Î| 207 cf |Ï| 208 d0 |Ð| 209 d1 |Ñ| 210 d2 |Ò| 211 d3 |Ó| 212 d4 |Ô| 213 d5 |Õ| 214 d6 |Ö| 215 d7 |×| 216 d8 |Ø| 217 d9 |Ù| 218 da |Ú| 219 db |Û| 220 dc |Ü| 221 dd |Ý| 222 de |Þ| 223 df |ß| 224 e0 |à| 225 e1 |á| 226 e2 |â| 227 e3 |ã| 228 e4 |ä| 229 e5 |å| 230 e6 |æ| 231 e7 |ç| 232 e8 |è| 233 e9 |é| 234 ea |ê| 235 eb |ë| 236 ec |ì| 237 ed |í| 238 ee |î| 239 ef |ï| 240 f0 |ð| 241 f1 |ñ| 242 f2 |ò| 243 f3 |ó| 244 f4 |ô| 245 f5 |õ| 246 f6 |ö| 247 f7 |÷| 248 f8 |ø| 249 f9 |ù| 250 fa |ú| 251 fb |û| 252 fc |ü| 253 fd |ý| 254 fe |þ| 255 ff |ÿ|
This version draws a more fancy table, positioning the items on the console monitor with ANSI control sequences:
<lang julia>print("\e[2J") # clear screen print("""
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║ """) # indent is set by this (least indented) line
for i = 0:14
a = string(i,base=16)
println( "$a ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ $a") println( " ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢") println(i==0 ? " ║dle│dc1│dc2│dc3│dc4│nak│syn│etb│can│ em│eof│esc│ fs│ gs│ rs│ us║"
: " ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║")
end println("""
f ║ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ║ f ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝ 0 1 2 3 4 5 6 7 8 9 A B C D E F """) # """ string is indented here
for i = 1:255
r,c = divrem(i,16) r,c = 3r+4,4c+5 i > 31 && print("\e[$(r-1);$(c-1)H$(lpad(i,3))") 6<i<11 || i==155 || i==173 || print("\e[$r;$(c)H$(Char(i))")
end print("\e[54;1H")</lang>
- Output:
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 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 32│ 33│ 34│ 35│ 36│ 37│ 38│ 39│ 40│ 41│ 42│ 43│ 44│ 45│ 46│ 47║ 2 ║ │ ! │ " │ # │ $ │ % │ & │ ' │ ( │ ) │ * │ + │ , │ - │ . │ / ║ 2 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 48│ 49│ 50│ 51│ 52│ 53│ 54│ 55│ 56│ 57│ 58│ 59│ 60│ 61│ 62│ 63║ 3 ║ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ : │ ; │ < │ = │ > │ ? ║ 3 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 64│ 65│ 66│ 67│ 68│ 69│ 70│ 71│ 72│ 73│ 74│ 75│ 76│ 77│ 78│ 79║ 4 ║ @ │ A │ B │ C │ D │ E │ F │ G │ H │ I │ J │ K │ L │ M │ N │ O ║ 4 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 80│ 81│ 82│ 83│ 84│ 85│ 86│ 87│ 88│ 89│ 90│ 91│ 92│ 93│ 94│ 95║ 5 ║ P │ Q │ R │ S │ T │ U │ V │ W │ X │ Y │ Z │ [ │ \ │ ] │ ^ │ _ ║ 5 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║ 96│ 97│ 98│ 99│100│101│102│103│104│105│106│107│108│109│110│111║ 6 ║ ` │ a │ b │ c │ d │ e │ f │ g │ h │ i │ j │ k │ l │ m │ n │ o ║ 6 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║112│113│114│115│116│117│118│119│120│121│122│123│124│125│126│127║ 7 ║ p │ q │ r │ s │ t │ u │ v │ w │ x │ y │ z │ { │ | │ } │ ~ │ � ║ 7 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║128│129│130│131│132│133│134│135│136│137│138│139│140│141│142│143║ 8 ║ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � ║ 8 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║144│145│146│147│148│149│150│151│152│153│154│155│156│157│158│159║ 9 ║ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ � │ │ � │ � │ � │ � ║ 9 ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║160│161│162│163│164│165│166│167│168│169│170│171│172│173│174│175║ a ║ │ ¡ │ ¢ │ £ │ ¤ │ ¥ │ ¦ │ § │ ¨ │ © │ ª │ « │ ¬ │ │ ® │ ¯ ║ a ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║176│177│178│179│180│181│182│183│184│185│186│187│188│189│190│191║ b ║ ° │ ± │ ² │ ³ │ ´ │ µ │ ¶ │ · │ ¸ │ ¹ │ º │ » │ ¼ │ ½ │ ¾ │ ¿ ║ b ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║192│193│194│195│196│197│198│199│200│201│202│203│204│205│206│207║ c ║ À │ Á │ Â │ Ã │ Ä │ Å │ Æ │ Ç │ È │ É │ Ê │ Ë │ Ì │ Í │ Î │ Ï ║ c ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║208│209│210│211│212│213│214│215│216│217│218│219│220│221│222│223║ d ║ Ð │ Ñ │ Ò │ Ó │ Ô │ Õ │ Ö │ × │ Ø │ Ù │ Ú │ Û │ Ü │ Ý │ Þ │ ß ║ d ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║224│225│226│227│228│229│230│231│232│233│234│235│236│237│238│239║ e ║ à │ á │ â │ ã │ ä │ å │ æ │ ç │ è │ é │ ê │ ë │ ì │ í │ î │ ï ║ e ╟───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───╢ ║240│241│242│243│244│245│246│247│248│249│250│251│252│253│254│255║ f ║ ð │ ñ │ ò │ ó │ ô │ õ │ ö │ ÷ │ ø │ ù │ ú │ û │ ü │ ý │ þ │ ÿ ║ f ╚═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╝ 0 1 2 3 4 5 6 7 8 9 A B C D E F
A similar output can be produced without ANSI control sequences, just filling up a huge string and printing it. Below is a general Object (struct) and the corresponding methods to draw a table of arbitrary shape in the console. It is the Julia way of OOP. The Table structure holds the relevant data and the constructor. The Base.iterate function extends the general iterate function, and allows using the field names in a function, w/o prefixing them with "<structName>." The function prt() fills up a string with data, formatting spaces and new-lines, and prints it to the console. <lang julia>#= CONSOLE TABLES =============================================================
rn: nrows, rh: height of rows cn: ncols, cw: width of columns T[rn,cn,rh] table data strings cr: rows in colum headers CH[cn,cr] column header strings of max cw length hl: lengths of row header strings RH[rn,rh] row header strings of max length hl
==============================================================================#
struct Table
rn::Int; rh::Int; cn::Int; cw::Int; T::Array{String,3} cr::Int; CH::Array{String,2} hl::Int; RH::Array{String,2} function Table(rn,rh,cn,cw,cr,hl) # constructor new(rn,rh,cn,cw,fill("",(rn,cn,rh)), # arrays initialized with empty strings cr,fill("",(cr,cn)), hl,fill("",(rn,rh))) end
end Base.iterate(T::Table,i=1) = i<=nfields(T) ? (getfield(T,i),i+1) : nothing
cpad(s::String,n::Integer) = (m=length(s))<n ? lpad(rpad(s,(n+m)>>1),n) : first(s,n)
function prt((rn,rh,cn,cw,T, cr,CH, hl,RH)::Table)
TL,TX,TR,BH = '╔','╤','╗','═' IL,IX,IR,IV,IH='╟','┼','╢','│','─' BL,BX,BR,BV = '╚','╧','╝','║'
u,v,w,d,t = BH^cw, IH^cw, " "^hl, cn-2, " "^hl b = w*(cn==1 ? IL*v*IR : IL*v*(IX*v)^d*IX*v*IR)*'\n' # internal separator for r = 1:cr for c = 1:cn t*=cpad(CH[r,c],cw+1) end t *= "\n$w" end
t *= (cn==1 ? TL*u*TR : TL*u*(TX*u)^d*TX*u*TR)*'\n' # top border for r = 1:rn for p = 1:rh s = cpad(RH[r,p],hl)*BV for c = 1:cn-1 s *= cpad(T[r,c,p],cw) * IV end t*= s * cpad(T[r,cn,p],cw) * BV *'\n' end t*=r<rn ? b : cn<2 ? w*BL*u*BR : w*BL*u*(BX*u)^d*BX*u*BR # bottom border end println("\n$t\n")
end</lang> Using these is simple, only provide the data, and prt it. <lang julia>Tbl = Table(16,2,16,3, 2,3) # construct table Tbl.CH[1,:] = string.(0:15,base=16) # Column headers Tbl.RH[:,2] = string.(0:15,base=16) # Row headers for i = 0:255 # populate table, exclude special characters
Tbl.T[i>>4+1,i&15+1,1:2]=["$i",i∈(0,7,8,9,10,13,27,155) ? "" : "$(Char(i))"]
end prt(Tbl) # format and print table on console</lang>
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
langur
<lang langur>for .i of 16 {
for .j = 31 + .i ; .j < 128 ; .j += 16 { val .L = given(.j; 32: "spc"; 127: "del"; cp2s .j) write $"\.j:3; : \.L:-4;" } writeln()
}</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
Lua
<lang lua> -- map of character values to desired representation local chars = setmetatable({[32] = "Spc", [127] = "Del"}, {__index = function(_, k) return string.char(k) end})
-- row iterator local function iter(s,a)
a = (a or s) + 16 if a <= 127 then return a, chars[a] end
end
-- print loop for i = 0, 15 do
for j, repr in iter, i+16 do io.write(("%3d : %3s "):format(j, repr)) end io.write"\n"
end</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
M2000 Interpreter
<lang M2000 Interpreter> Function ProduceAscii$ { Document Ascii$="\" DelUnicode$=ChrCode$(0x2421) j=2 Print Ascii$; For i=0 to 15 Print Hex$(i, .5); Ascii$=Hex$(i, .5) Next For i=32 to 126 If pos>16 then Ascii$={ }+Hex$(j, .5) Print : Print Hex$(j, .5);: j++ End if Print Chr$(i); Ascii$=Chr$(i) Next Print DelUnicode$ =Ascii$+DelUnicode$+{ } } Clipboard ProduceAscii$() </lang>
- Output:
\0123456789ABCDEF 2 !"#$%&'()*+,-./ 30123456789:;<=>? 4@ABCDEFGHIJKLMNO 5PQRSTUVWXYZ[\]^_ 6`abcdefghijklmno 7pqrstuvwxyz{|}~␡
MiniScript
<lang MiniScript>// Prints ASCII table // Note changing the values of startChar and endChar will print // a flexible table in that range
startChar = 32 endChar = 127 characters = []
for i in range(startChar, endChar)
addString = char(i) + " " if i == 32 then addString = "SPC" if i == 127 then addString = "DEL" characters.push addString
end for
for i in characters.indexes
iNum = i + startChar iChar = " " + str(iNum) characters[i] = iChar[-5:] + " : " + characters[i]
end for
columns = 6 line = "" col = 0 for out in characters
col = col + 1 line = line + out if col == columns then print line line = "" col = 0 end if
end for if line then print line // final check for odd incomplete line output</lang>
- Output:
32 : SPC 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
Nanoquery
<lang Nanoquery>k = "" for i in range(0, 15) for j in range(32 + i, 127, 16) if j = 32 k = "Spc" else if j = 127 k = "Del" else k = chr(j) end print format("%3d : %-3s ", j, k) end println end</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
Nim
<lang Nim>import strformat
for i in 0..15:
for j in countup(32 + i, 127, step = 16): var k = "" case j of 32: k = "Spc" of 127: k = "Del" else: k = $char(j) write(stdout, fmt"{j:3d} : {k:<6s}") write(stdout, "\n")</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
Objeck
<lang objeck>class AsciiTable {
function : Main(args : String[]) ~ Nil { for(i := 32; i <= 127 ; i += 1;) { if(i = 32 | i = 127) { s := i = 32 ? "Spc" : "Del"; "{$i}:\t{$s}\t"->Print(); } else { c := i->ToChar(); "{$i}:\t{$c}\t"->Print(); }; if((i-1) % 6 = 0 ) { "\n"->Print(); }; }; }
}</lang>
- Output:
32: Spc 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
Perl
Output in the same style as Raku.
<lang perl>use charnames ':full'; binmode STDOUT, ':utf8';
sub glyph {
my($n) = @_; if ($n < 33) { chr 0x2400 + $n } # display symbol names for invisible glyphs elsif ($n==124) { '|' } elsif ($n==127) { 'DEL' } else { chr $n }
}
print qq[{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"\n];
for (0..127) {
print qq[|-\n] unless $_ % 16;; printf qq[|%d
0x%02X
%s\n], $_, $_, charnames::viacode($_), glyph($_); }
} print qq[|}\n];</lang>
Phix
<lang Phix>sequence ascii = {} for ch=32 to 127 do
ascii = append(ascii,sprintf("%4d (#%02x): %c ",ch))
end for puts(1,substitute(join_by(ascii,16,6),x"7F","del"))</lang>
- Output:
32 (#20): 48 (#30): 0 64 (#40): @ 80 (#50): P 96 (#60): ` 112 (#70): p 33 (#21): ! 49 (#31): 1 65 (#41): A 81 (#51): Q 97 (#61): a 113 (#71): q 34 (#22): " 50 (#32): 2 66 (#42): B 82 (#52): R 98 (#62): b 114 (#72): r 35 (#23): # 51 (#33): 3 67 (#43): C 83 (#53): S 99 (#63): c 115 (#73): s 36 (#24): $ 52 (#34): 4 68 (#44): D 84 (#54): T 100 (#64): d 116 (#74): t 37 (#25): % 53 (#35): 5 69 (#45): E 85 (#55): U 101 (#65): e 117 (#75): u 38 (#26): & 54 (#36): 6 70 (#46): F 86 (#56): V 102 (#66): f 118 (#76): v 39 (#27): ' 55 (#37): 7 71 (#47): G 87 (#57): W 103 (#67): g 119 (#77): w 40 (#28): ( 56 (#38): 8 72 (#48): H 88 (#58): X 104 (#68): h 120 (#78): x 41 (#29): ) 57 (#39): 9 73 (#49): I 89 (#59): Y 105 (#69): i 121 (#79): y 42 (#2A): * 58 (#3A): : 74 (#4A): J 90 (#5A): Z 106 (#6A): j 122 (#7A): z 43 (#2B): + 59 (#3B): ; 75 (#4B): K 91 (#5B): [ 107 (#6B): k 123 (#7B): { 44 (#2C): , 60 (#3C): < 76 (#4C): L 92 (#5C): \ 108 (#6C): l 124 (#7C): | 45 (#2D): - 61 (#3D): = 77 (#4D): M 93 (#5D): ] 109 (#6D): m 125 (#7D): } 46 (#2E): . 62 (#3E): > 78 (#4E): N 94 (#5E): ^ 110 (#6E): n 126 (#7E): ~ 47 (#2F): / 63 (#3F): ? 79 (#4F): O 95 (#5F): _ 111 (#6F): o 127 (#7F): del
PHP
<lang PHP><?php
echo '+' . str_repeat('----------+', 6), PHP_EOL; for ($j = 0 ; $j < 16 ; $j++) {
for ($i = 0 ; $i < 6 ; $i++) { $val = 32 + $i * 16 + $j; switch ($val) { case 32: $chr = 'Spc'; break; case 127: $chr = 'Del'; break; default: $chr = chr($val) ; break; } echo sprintf('| %3d: %3s ', $val, $chr); } echo '|', PHP_EOL;
} echo '+' . str_repeat('----------+', 6), PHP_EOL;</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 | +----------+----------+----------+----------+----------+----------+
Prolog
<lang Prolog>ascii :-
forall(between(32, 47, N), row(N)).
row(N) :- N > 127, nl, !. row(N) :-
code(N), ascii(N), Nn is N + 16, row(Nn).
code(N) :- N < 100, format(' ~d : ', N). code(N) :- N >= 100, format(' ~d : ', N).
ascii(32) :- write(' Spc '), !. ascii(127) :- write(' Del '), !. ascii(A) :- char_code(D,A), format(' ~w ', D).</lang>
- Output:
?- ascii. 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 true. ?-
PureBasic
<lang PureBasic>If OpenConsole("Show_Ascii_table: rosettacode.org")
Define r.i, c.i For r=0 To 15 For c=32+r To 112+r Step 16 Print(RSet(Str(c),3)+" : ") Select c Case 32 Print("Spc") Case 127 Print("Del") Default Print(LSet(Chr(c),3)) EndSelect Print(Space(3)) Next PrintN("") Next Input()
EndIf</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
Python
Imperative
<lang python> for i in range(16):
for j in range(32+i, 127+1, 16): if j == 32: k = 'Spc' elif j == 127: k = 'Del' else: k = chr(j) print("%3d : %-3s" % (j,k), end="") print()
</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
HTML
After Raku, 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 ␡ |
Plain text
Composed from generic abstractions: <lang python>Plain text ASCII code table
from functools import reduce from itertools import chain
- asciiTable :: String
def asciiTable():
Table of ASCII codes arranged in 16 rows * 6 columns. return unlines( concat(c.ljust(12, ' ') for c in xs) for xs in ( transpose(chunksOf(16)( [asciiEntry(n) for n in enumFromTo(32)(127)] )) ) )
- asciiEntry :: Int -> String
def asciiEntry(n):
Number, and name or character, for given point in ASCII code. k = asciiName(n) return k if == k else ( concat([str(n).rjust(3, ' '), ' : ', k]) )
- asciiName :: Int -> String
def asciiName(n):
Name or character for given ASCII code. return if 32 > n or 127 < n else ( 'Spc' if 32 == n else ( 'Del' if 127 == n else chr(n) ) )
- TEST ----------------------------------------------------
- main :: IO ()
def main():
Test print( asciiTable() )
- GENERIC ABSTRACTIONS ------------------------------------
- chunksOf :: Int -> [a] -> a
def chunksOf(n):
A series of lists of length n, subdividing the contents of xs. Where the length of xs is not evenly divible the final list will be shorter than n. return lambda xs: reduce( lambda a, i: a + [xs[i:n + i]], range(0, len(xs), n), [] ) if 0 < n else []
- concat :: a -> [a]
- concat :: [String] -> String
def concat(xxs):
The concatenation of all the elements in a list. xs = list(chain.from_iterable(xxs)) unit = if isinstance(xs, str) else [] return unit if not xs else ( .join(xs) if isinstance(xs[0], str) else xs )
- enumFromTo :: (Int, Int) -> [Int]
def enumFromTo(m):
Integer enumeration from m to n. return lambda n: list(range(m, 1 + n))
- splitAt :: Int -> [a] -> ([a], [a])
def splitAt(n):
A tuple pairing the prefix of length n with the rest of xs. return lambda xs: (xs[0:n], xs[n:])
- transpose :: Matrix a -> Matrix a
def transpose(m):
The rows and columns of the argument transposed. (The matrix containers and rows can be lists or tuples). if m: inner = type(m[0]) z = zip(*m) return (type(m))( map(inner, z) if tuple != inner else z ) else: return m
- unlines :: [String] -> String
def unlines(xs):
A single newline-delimited string derived from a list of strings. return '\n'.join(xs)
- MAIN ---
if __name__ == '__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
List Comprehensions
<lang python>
- One-liner
- print('\n'.join([.join(["%3d : %-3s" % (a, 'Spc' if a == 32 else 'Del' if a == 127 else chr(a)) for a in lst]) for lst in [[i+c*16 for c in range(6)] for i in range(32, 47+1)]])
- Detailed version
- List of 16 lists of integers corresponding to
- each row of the table
rows_as_ints = [[i+c*16 for c in range(6)] for i in range(32, 47+1)]
- Function for converting numeric value to string
codepoint2str = lambda codepoint: 'Spc' if codepoint == 32 else 'Del' if codepoint == 127 else chr(codepoint)
rows_as_strings = [["%3d : %-3s" % (a, codepoint2str(a)) for a in row] for row in rows_as_ints]
- Joining columns into rows and printing rows one in a separate line
print('\n'.join([.join(row) for row in rows_as_strings]))</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
R
<lang rsplus>chr <- function(n) {
rawToChar(as.raw(n))
}
idx <- 32 while (idx < 128) {
for (i in 0:5) {
num <- idx + i if (num<100) cat(" ")
cat(num,": ")
if (num == 32) { cat("Spc "); next }
if (num == 127) { cat("Del "); next }
cat(chr(num)," ")
} idx <- idx + 6 cat("\n")
}</lang>
- Output:
32 : Spc 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
Racket
<lang racket>#lang racket
(for ([i (in-range 16)])
(for ([j (in-range 6)]) (define n (+ 32 (* j 16) i)) (printf "~a : ~a" (~a n #:align 'right #:min-width 3) (~a (match n [32 "SPC"] [127 "DEL"] [_ (integer->char n)]) #:min-width 5))) (newline))</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 : %br> 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
Raku
(formerly 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 ␡ |
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 (those that have a 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 "
@.= @.1= "x'07' x'08' x'09' x'0a' x'0d' x'1a' x'1b' x'20'" @.2= "bel b/s tab l/f c/r eof esc bla" @.3= "bell backspace tabchar linefeed carriage end-of- escape blank" @.4= " return file" @.5= copies('≈', 79)
do a=1 for 8; say @.a /*display header info (abbreviations).*/ end /*a*/ /*also included are three blank lines. */
b= ' '; hdr= left(b, 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(b, 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 b; _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( d2c(#), 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= b; do k=0 for 16; _=_||b d2x(k)b; end; say _; say; return grid: arg $1,$2,$3,$4; _=hdr; do 16; _=_ || $1 || $4; $1= $2; end; say _ || $3; return</lang>
- output showing a horizontal formatted grid (table):
(Code page 437 was used for the example below using DOS under Microsoft Windows.)
x'07' x'08' x'09' x'0a' x'0d' x'1a' x'1b' x'20' bel b/s tab l/f c/r eof esc bla bell backspace tabchar linefeed carriage end-of- escape blank return file ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈ 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:
Ruby
<lang ruby>chars = (32..127).map do |ord|
k = case ord when 32 then "␠" when 127 then "␡" else ord.chr end "#{ord.to_s.ljust(3)}: #{k}"
end
chars.each_slice(chars.size/6).to_a.transpose.each{|s| puts s.join(" ")}</lang>
- Output:
32 : ␠ 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: ␡
Rust
<lang Rust>fn main() {
for i in 0u8..16 { for j in ((32+i)..128).step_by(16) { let k = (j as char).to_string(); print!("{:3} : {:<3} ", j, match j { 32 => "Spc", 127 => "Del", _ => &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
Scala
- Output:
Best seen in running your browser either by ScalaFiddle (your local ES aka JavaScript execution, non JVM) or Scastie (remote JVM).
<lang Scala>object AsciiTable extends App {
val (strtCharVal, lastCharVal, nColumns) = (' '.toByte, '\u007F'.toByte, 6) require(nColumns % 2 == 0, "Number of columns must be even.")
val nChars = lastCharVal - strtCharVal + 1 val step = nChars / nColumns val threshold = strtCharVal + (nColumns - 1) * step
def indexGen(start: Byte): LazyList[Byte] = start #:: indexGen( (if (start >= threshold) strtCharVal + start % threshold + 1 else start + step).toByte )
def k(j: Byte): Char = j match { case `strtCharVal` => '\u2420' case 0x7F => '\u2421' case _ => j.toChar }
indexGen(strtCharVal) .take(nChars) .sliding(nColumns, nColumns) .map(_.map(byte => f"$byte%3d : ${k(byte)}")) .foreach(line => println(line.mkString(" ")))
}</lang>
Seed7
<lang seed7>$ include "seed7_05.s7i";
const proc: main is func
local var integer: row is 0; var integer: column is 0; var integer: number is 0; begin for row range 0 to 15 do for column range 0 to 5 do number := 32 + 16 * column + row; write(number lpad 3 <& " : "); case number of when {32}: write("Spc "); when {127}: write("Del "); otherwise: write(chr(number) <& " "); end case; end for; writeln; end for; end func;</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
Spin
<lang spin>con
_clkmode = xtal1+pll16x _clkfreq = 80_000_000
obj
ser : "FullDuplexSerial"
pub main | i, j
ser.start(31, 30, 0, 115200)
repeat i from 0 to 15 repeat j from i + 32 to 127 step 16 if j < 100 ser.tx(32) ser.dec(j) ser.str(string(": ")) case j 32: ser.str(string("SPC")) 127: ser.str(string("DEL")) other: ser.tx(j) ser.str(string(" ")) ser.str(string(" ")) ser.str(string(13, 10))
waitcnt(_clkfreq + cnt) ser.stop</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
Standard ML
<lang>fun Table n 127 = " 127: 'DEL'\n"
| Table 0 x = "\n" ^ (Table 10 x) | Table n x = (StringCvt.padLeft #" " 4 (Int.toString x)) ^ ": '" ^ (str (chr x)) ^ "' " ^ ( Table (n-1) (x+1)) ;
print (Table 10 32) ;</lang>
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'
Tcl
<lang Tcl> for {set i 0} {$i < 16} {incr i} {
for {set j $i} {$j < 128} {incr j 16} { if {$j <= 31} { continue ;# don't show values 0 - 31 } elseif {$j == 32} { set x "SP" } elseif {$j == 127} { set x "DEL" } else { set x [format %c $j] } puts -nonewline [format "%3d: %-5s" $j $x] } puts ""
} </lang>
- Output:
32: SP 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
VBA
<lang VB> Public Sub ascii()
Dim s As String, i As Integer, j As Integer For i = 0 To 15 For j = 32 + i To 127 Step 16 Select Case j Case 32: s = "Spc" Case 127: s = "Del" Case Else: s = Chr(j) End Select Debug.Print Tab(10 * (j - 32 - i) / 16); Spc(3 - Len(CStr(j))); j & ": " & s; Next j Debug.Print vbCrLf Next i
End Sub</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
Visual Basic .NET
<lang vbnet>Imports System.Console Imports System.Linq.Enumerable
Module Program
Sub Main() Dim Text = Function(index As Integer) If(index = 32, "Sp", If(index = 127, "Del", ChrW(index) & ""))
Dim start = 32 Do WriteLine(String.Concat(Range(0, 6).Select(Function(i) $"{start + 16 * i, -3} : {Text(start + 16 * i), -6}"))) start += 1 Loop While start + 16 * 5 < 128 End Sub
End Module</lang>
- Output:
32 : Sp 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
Wren
<lang ecmascript>import "/fmt" for Fmt
for (i in 0...16) {
var j = 32 + i while (j < 128) { var k = "%(String.fromByte(j))" if (j == 32) { k = "Spc" } else if (j == 127) { k = "Del" } System.write("%(Fmt.d(3, j)) : %(Fmt.s(-3, k)) ") j = j + 16 } System.print()
}</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
XPL0
<lang XPL0>int Hi, Lo; [SetHexDigits(2); Text(0, " "); for Hi:= 2 to 7 do
[HexOut(0, Hi*16); Text(0, " ")];
CrLf(0); for Lo:= 0 to $F do
[HexOut(0, Lo); Text(0, " "); for Hi:= 2 to 7 do [ChOut(0, Hi*16+Lo); Text(0, " ")]; CrLf(0); ];
]</lang>
- Output:
20 30 40 50 60 70 00 0 @ P ` p 01 ! 1 A Q a q 02 " 2 B R b r 03 # 3 C S c s 04 $ 4 D T d t 05 % 5 E U e u 06 & 6 F V f v 07 ' 7 G W g w 08 ( 8 H X h x 09 ) 9 I Y i y 0A * : J Z j z 0B + ; K [ k { 0C , < L \ l | 0D - = M ] m } 0E . > N ^ n ~ 0F / ? O _ o
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
ZX Spectrum Basic
Note in particular entries 94, 96 and 127. <lang zxbasic>10 FOR x=0 TO 9 20 PRINT AT 0,4+2*x;x 30 PRINT AT x+1,0;10*(3+x) 40 NEXT x 50 FOR x=32 TO 127 60 LET d=x-10*INT (x/10) 70 LET t=(x-d)/10 80 PRINT AT t-2,4+2*d;CHR$ x 90 NEXT x</lang>
- Output:
0 1 2 3 4 5 6 7 8 9 30 ! " # $ % & ' 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 { | } ~ ©
- Programming Tasks
- Solutions by Programming Task
- 6502 Assembly
- 8080 Assembly
- 8086 Assembly
- Ada
- ALGOL 68
- ALGOL W
- APL
- AppleScript
- AutoHotKey
- AWK
- C
- C++
- C sharp
- Caché ObjectScript
- Clojure
- Commodore BASIC
- Pages with broken file links
- Common Lisp
- Dc
- Delphi
- Factor
- Forth
- Fortran
- FreeBASIC
- Free Pascal
- Go
- Haskell
- IS-BASIC
- J
- Java
- JavaScript
- Jsish
- Julia
- Kotlin
- Langur
- Lua
- M2000 Interpreter
- MiniScript
- Nanoquery
- Nim
- Objeck
- Perl
- Phix
- PHP
- Prolog
- PureBasic
- Python
- R
- Racket
- Raku
- REXX
- Ring
- Ruby
- Rust
- Scala
- Seed7
- Spin
- Standard ML
- Tcl
- VBA
- Visual Basic .NET
- Wren
- Wren-fmt
- XPL0
- Zkl
- ZX Spectrum Basic