Show ASCII table
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Show the ASCII character set from values 32 to 127 (decimal) in a table format.
- Metrics
- Counting
- Word frequency
- Letter frequency
- Jewels and stones
- I before E except after C
- Bioinformatics/base count
- Count occurrences of a substring
- Count how many vowels and consonants occur in a string
- Remove/replace
- XXXX redacted
- Conjugate a Latin verb
- Remove vowels from a string
- String interpolation (included)
- Strip block comments
- Strip comments from a string
- Strip a set of characters from a string
- Strip whitespace from a string -- top and tail
- Strip control codes and extended characters from a string
- Anagrams/Derangements/shuffling
- Word wheel
- ABC problem
- Sattolo cycle
- Knuth shuffle
- Ordered words
- Superpermutation minimisation
- Textonyms (using a phone text pad)
- Anagrams
- Anagrams/Deranged anagrams
- Permutations/Derangements
- Find/Search/Determine
- ABC words
- Odd words
- Word ladder
- Semordnilap
- Word search
- Wordiff (game)
- String matching
- Tea cup rim text
- Alternade words
- Changeable words
- State name puzzle
- String comparison
- Unique characters
- Unique characters in each string
- Extract file extension
- Levenshtein distance
- Palindrome detection
- Common list elements
- Longest common suffix
- Longest common prefix
- Compare a list of strings
- Longest common substring
- Find common directory path
- Words from neighbour ones
- Change e letters to i in words
- Non-continuous subsequences
- Longest common subsequence
- Longest palindromic substrings
- Longest increasing subsequence
- Words containing "the" substring
- Sum of the digits of n is substring of n
- Determine if a string is numeric
- Determine if a string is collapsible
- Determine if a string is squeezable
- Determine if a string has all unique characters
- Determine if a string has all the same characters
- Longest substrings without repeating characters
- Find words which contains all the vowels
- Find words which contain the most consonants
- Find words which contains more than 3 vowels
- Find words whose first and last three letters are equal
- Find words with alternating vowels and consonants
- Formatting
- Substring
- Rep-string
- Word wrap
- String case
- Align columns
- Literals/String
- Repeat a string
- Brace expansion
- Brace expansion using ranges
- Reverse a string
- Phrase reversals
- Comma quibbling
- Special characters
- String concatenation
- Substring/Top and tail
- Commatizing numbers
- Reverse words in a string
- Suffixation of decimal numbers
- Long literals, with continuations
- Numerical and alphabetical suffixes
- Abbreviations, easy
- Abbreviations, simple
- Abbreviations, automatic
- Song lyrics/poems/Mad Libs/phrases
- Mad Libs
- Magic 8-ball
- 99 bottles of beer
- The Name Game (a song)
- The Old lady swallowed a fly
- The Twelve Days of Christmas
- Tokenize
- Text between
- Tokenize a string
- Word break problem
- Tokenize a string with escaping
- Split a character string based on change of character
- Sequences
11l
L(i) 16
L(j) (32 + i .. 127).step(16)
String k
I j == 32
k = ‘Spc’
E I j == 127
k = ‘Del’
E
k = Char(code' j)
print(‘#3 : #<3’.format(j, k), end' ‘’)
print()
- 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
6502 Assembly
==========================================================================
; 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
8080 Assembly
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
- 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
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
- 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
Action!
Atari 8-bit computers use ATASCII character set which is a variation of ASCII.
PROC Main()
BYTE
count=[96],rows=[16],
first=[32],last=[127],
i,j
Put(125) ;clear screen
FOR i=0 TO rows-1
DO
Position(2,3+i)
FOR j=first+i TO last STEP rows
DO
IF j>=96 AND j<=99 THEN
Put(' )
FI
PrintB(j)
Put(' )
IF j=32 THEN
Print("SP ")
ELSEIF j=125 THEN
Print("CL")
ELSEIF j=126 THEN
Print("DL")
ELSEIF j=127 THEN
Print("TB")
ELSE
PrintF("%C ",j)
FI
OD
PutE()
OD
RETURN
- Output:
Screenshot from Atari 8-bit computer
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 CL 46 . 62 > 78 N 94 ^ 110 n 126 DL 47 / 63 ? 79 O 95 _ 111 o 127 TB
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;
- 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
# generate an ascii table for characters 32 - 127 #
FOR c FROM 32 TO 32 + 15 DO
FOR ach FROM c BY 16 TO c + ( 16 * 5 ) DO
print( ( whole( ach, -4 )
, ": "
, IF ach = 32 THEN "SPC"
ELIF ach = 127 THEN "DEL"
ELSE " " + REPR ach + " "
FI
)
)
OD;
print( ( newline ) )
OD
- 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 W
This assumes the ASCII character set is used by the Algol W compiler/runtime - the original Algol W implementation used EBCDIC.
% generate an ascii table for chars 32 - 127 %
for i := 32 until 32 + 15 do begin
write();
for c := i step 16 until i + ( 16 * 5 ) do begin
writeon( i_w := 3, s_w := 0, c, ": " );
if c = 32 then writeon( "Spc ")
else if c = 127 then writeon( "Del " )
else writeon( code( c ), " " )
end for_ach
end for_i.
- 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
APL
{(¯3↑⍕⍵),': ',∊('Spc' 'Del'(⎕UCS ⍵))[32 127⍳⍵]}¨⍉6 16⍴31+⍳96
- 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
-- 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
- 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
Applesoft BASIC
This is similar to the Commodore BASIC program in that it clears the screen and displays the version of BASIC. It uses enterable Applesoft BASIC to embed a 6502 machine language routine that XORs $87 with the character stored at $41 and prints the character.
0 GOTO 10: ONERR AI READ LY RND
10 LET X = 256 * PEEK (104)
11 LET X = X + PEEK (103) + 7
20 CALL - 1184:B$ = CHR$ (8)
21 NORMAL : PRINT :E = 61588
22 PRINT TAB( 29)"APPLESOFT";
23 PRINT " II"B$:M = - 1
24 PRINT TAB( 22)"BASED ON ";
25 FOR I = E + 9 TO E STEP M
26 POKE 65, PEEK (I): CALL X
27 NEXT : PRINT B$:S$ = " "
28 PRINT TAB( 28)"6502 ";
29 PRINT "BASIC V2" CHR$ (8)
30 PRINT "CHARACTER SET"
40 FOR R = 0 TO 15: PRINT
50 FOR C = 2 TO 7:A = C * 16
60 LET N$ = S$ + STR$ (A + R)
70 LET N$ = RIGHT$ (N$,4)
80 PRINT N$":" CHR$ (A + R);
90 NEXT C,R: PRINT
The 6502 routine is embedded at line 0 and is used to display the string "!TFOSORCIM" backwards.
LDA $41 ; ONERR A
EOR #$87 ; I READ
JMP $DB59 ; LY RND
ARM Assembly
Thanks to Keith of ChibiAkumas for creating the GBA bitmap font and I/O routines.
.equ CursorX,0x02000000
.equ CursorY,0x02000001
ProgramStart:
mov sp,#0x03000000 ;Init Stack Pointer
mov r4,#0x04000000 ;DISPCNT -LCD Control
mov r2,#0x403 ;4= Layer 2 on / 3= ScreenMode 3
str r2,[r4] ;now the screen is visible
bl ResetTextCursors ;set text cursors to top left of screen
mov r2,#32
mov r3,#32+20 ;screen height is 20 chars
mov r5,#0 ;column spacer
mov r6,#5
;R0 = Character to print (working copy)
;R2 = real copy
;R3 = compare factor
loop_printAscii:
mov r0,r2
bl ShowHex
mov r0,#32
bl PrintChar
mov r0,r2
bl PrintChar
bl CustomNewLine
add r2,r2,#1
cmp r2,#128
beq forever ;exit early
cmp r2,r3
bne loop_printAscii
add r3,r3,#20 ;next section
;inc to next column
add r5,r5,#5
mov r0,r5
mov r1,#0
bl SetTextCursors
subs r6,r6,#1
bne loop_printAscii
forever:
b forever
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; INPUT/OUTPUT SUBROUTINES - CREATED BY KEITH OF CHIBIAKUMAS.COM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintString: ;Print 255 terminated string
STMFD sp!,{r0-r12, lr}
PrintStringAgain:
ldrB r0,[r1],#1
cmp r0,#255
beq PrintStringDone ;Repeat until 255
bl printchar ;Print Char
b PrintStringAgain
PrintStringDone:
LDMFD sp!,{r0-r12, pc}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PrintChar:
STMFD sp!,{r0-r12, lr}
mov r4,#0
mov r5,#0
mov r3,#CursorX
ldrB r4,[r3] ;X pos
mov r3,#CursorY
ldrB r5,[r3] ;Y pos
mov r3,#0x06000000 ;VRAM base
mov r6,#8*2 ;Xpos, 2 bytes per pixel, 8 bytes per char
mul r2,r4,r6
add r3,r3,r2
mov r4,#240*8*2 ;Ypos, 240 pixels per line,
mul r2,r5,r4 ;2 bytes per pixel, 8 lines per char
add r3,r3,r2
adr r4,BitmapFont ;Font source
sub r0,r0,#32 ;First Char is 32 (space)
add r4,r4,r0,asl #3 ;8 bytes per char
mov r1,#8 ;8 lines
DrawLine:
mov r7,#8 ;8 pixels per line
ldrb r8,[r4],#1 ;Load Letter
mov r9,#0b100000000 ;Mask
mov r2, #0b1111111101000000; Color: ABBBBBGGGGGRRRRR A=Alpha
DrawPixel:
tst r8,r9 ;Is bit 1?
strneh r2,[r3] ;Yes? then fill pixel (HalfWord)
add r3,r3,#2
mov r9,r9,ror #1 ;Bitshift Mask
subs r7,r7,#1
bne DrawPixel ;Next Hpixel
add r3,r3,#480-16 ;Move Down a line (240 pixels *2 bytes)
subs r1,r1,#1 ;-1 char (16 px)
bne DrawLine ;Next Vline
LineDone:
mov r3,#CursorX
ldrB r0,[r3]
add r0,r0,#1 ;Move across screen
strB r0,[r3]
mov r10,#30
cmp r0,r10
bleq NewLine
LDMFD sp!,{r0-r12, pc}
NewLine:
STMFD sp!,{r0-r12, lr}
mov r3,#CursorX
mov r0,#0
strB r0,[r3]
mov r4,#CursorY
ldrB r0,[r4]
add r0,r0,#1
strB r0,[r4]
LDMFD sp!,{r0-r12, pc}
CustomNewLine:
STMFD sp!,{r0-r12, lr}
mov r3,#CursorX
mov r0,r5
strB r0,[r3]
mov r4,#CursorY
ldrB r0,[r4]
add r0,r0,#1
strB r0,[r4]
LDMFD sp!,{r0-r12, pc}
ResetTextCursors:
STMFD sp!,{r4-r6,lr}
mov r4,#0
mov r5,#CursorX
mov r6,#CursorY
strB r4,[r5]
strB r4,[r6]
LDMFD sp!,{r4-r6,lr}
bx lr
SetTextCursors:
;input: R0 = new X
; R1 = new Y
STMFD sp!,{r5-r6}
mov r5,#CursorX
mov r6,#CursorY
strB r0,[r5]
strB r1,[r6]
LDMFD sp!,{r5-r6}
bx lr
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ShowHex:
STMFD sp!,{r0-r12, lr}
mov r2,r0,ror #4
bl ShowHexChar
mov r2,r0
bl ShowHexChar
LDMFD sp!,{r0-r12, pc}
ShowHexChar:
STMFD sp!,{r0-r12, lr}
;mov r3,
and r0,r2,#0x0F ; r3
cmp r0,#10
addge r0,r0,#7 ;if 10 or greater convert to alphabet letters a-f
add r0,r0,#48
bl PrintChar
LDMFD sp!,{r0-r12, pc}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BitmapFont:
;each byte represents a row of 8 pixels. This is a 1BPP font that is converted to the GBA's 16bpp screen format at runtime
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 20
.byte 0x10,0x18,0x18,0x18,0x18,0x00,0x18,0x00 ; 21
.byte 0x28,0x6C,0x28,0x00,0x00,0x00,0x00,0x00 ; 22
.byte 0x00,0x28,0x7C,0x28,0x7C,0x28,0x00,0x00 ; 23
.byte 0x18,0x3E,0x48,0x3C,0x12,0x7C,0x18,0x00 ; 24
.byte 0x02,0xC4,0xC8,0x10,0x20,0x46,0x86,0x00 ; 25
.byte 0x10,0x28,0x28,0x72,0x94,0x8C,0x72,0x00 ; 26
.byte 0x0C,0x1C,0x30,0x00,0x00,0x00,0x00,0x00 ; 27
.byte 0x18,0x18,0x30,0x30,0x30,0x18,0x18,0x00 ; 28
.byte 0x18,0x18,0x0C,0x0C,0x0C,0x18,0x18,0x00 ; 29
.byte 0x08,0x49,0x2A,0x1C,0x14,0x22,0x41,0x00 ; 2A
.byte 0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00 ; 2B
.byte 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30 ; 2C
.byte 0x00,0x00,0x00,0x7E,0x7E,0x00,0x00,0x00 ; 2D
.byte 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00 ; 2E
.byte 0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00 ; 2F
.byte 0x7C,0xC6,0xD6,0xD6,0xD6,0xC6,0x7C,0x00 ; 30
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 31
.byte 0x3C,0x7E,0x06,0x3C,0x60,0x7E,0x3C,0x00 ; 32
.byte 0x3C,0x7E,0x06,0x1C,0x06,0x7E,0x3C,0x00 ; 33
.byte 0x18,0x3C,0x64,0xCC,0x7C,0x0C,0x08,0x00 ; 34
.byte 0x3C,0x7E,0x60,0x7C,0x06,0x7E,0x3E,0x00 ; 35
.byte 0x3C,0x7E,0x60,0x7C,0x66,0x66,0x3C,0x00 ; 36
.byte 0x3C,0x7E,0x06,0x0C,0x18,0x18,0x10,0x00 ; 37
.byte 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00 ; 38
.byte 0x3C,0x66,0x66,0x3E,0x06,0x7E,0x3C,0x00 ; 39
.byte 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x00 ; 3A
.byte 0x00,0x00,0x18,0x18,0x00,0x18,0x18,0x30 ; 3B
.byte 0x0C,0x1C,0x38,0x60,0x38,0x1C,0x0C,0x00 ; 3C
.byte 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00 ; 3D
.byte 0x60,0x70,0x38,0x0C,0x38,0x70,0x60,0x00 ; 3E
.byte 0x3C,0x76,0x06,0x1C,0x00,0x18,0x18,0x00 ; 3F
.byte 0x7C,0xCE,0xA6,0xB6,0xC6,0xF0,0x7C,0x00 ; 40 @
.byte 0x18,0x3C,0x66,0x66,0x7E,0x66,0x24,0x00 ; 41 A
.byte 0x3C,0x66,0x66,0x7C,0x66,0x66,0x3C,0x00 ; 42 B
.byte 0x38,0x7C,0xC0,0xC0,0xC0,0x7C,0x38,0x00 ; 43 C
.byte 0x3C,0x64,0x66,0x66,0x66,0x64,0x38,0x00 ; 44 D
.byte 0x3C,0x7E,0x60,0x78,0x60,0x7E,0x3C,0x00 ; 45 E
.byte 0x38,0x7C,0x60,0x78,0x60,0x60,0x20,0x00 ; 46 F
.byte 0x3C,0x66,0xC0,0xC0,0xCC,0x66,0x3C,0x00 ; 47 G
.byte 0x24,0x66,0x66,0x7E,0x66,0x66,0x24,0x00 ; 48 H
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 49 I
.byte 0x08,0x0C,0x0C,0x0C,0x4C,0xFC,0x78,0x00 ; 4A J
.byte 0x24,0x66,0x6C,0x78,0x6C,0x66,0x24,0x00 ; 4B K
.byte 0x20,0x60,0x60,0x60,0x60,0x7E,0x3E,0x00 ; 4C L
.byte 0x44,0xEE,0xFE,0xD6,0xD6,0xD6,0x44,0x00 ; 4D M
.byte 0x44,0xE6,0xF6,0xDE,0xCE,0xC6,0x44,0x00 ; 4E N
.byte 0x38,0x6C,0xC6,0xC6,0xC6,0x6C,0x38,0x00 ; 4F O
.byte 0x38,0x6C,0x64,0x7C,0x60,0x60,0x20,0x00 ; 50 P
.byte 0x38,0x6C,0xC6,0xC6,0xCA,0x74,0x3A,0x00 ; 51 Q
.byte 0x3C,0x66,0x66,0x7C,0x6C,0x66,0x26,0x00 ; 52 R
.byte 0x3C,0x7E,0x60,0x3C,0x06,0x7E,0x3C,0x00 ; 53 S
.byte 0x3C,0x7E,0x18,0x18,0x18,0x18,0x08,0x00 ; 54 T
.byte 0x24,0x66,0x66,0x66,0x66,0x66,0x3C,0x00 ; 55 U
.byte 0x24,0x66,0x66,0x66,0x66,0x3C,0x18,0x00 ; 56 V
.byte 0x44,0xC6,0xD6,0xD6,0xFE,0xEE,0x44,0x00 ; 57 W
.byte 0xC6,0x6C,0x38,0x38,0x6C,0xC6,0x44,0x00 ; 58 X
.byte 0x24,0x66,0x66,0x3C,0x18,0x18,0x08,0x00 ; 59 Y
.byte 0x7C,0xFC,0x0C,0x18,0x30,0x7E,0x7C,0x00 ; 5A Z
.byte 0x1C,0x30,0x30,0x30,0x30,0x30,0x1C,0x00 ; 5B [
.byte 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x00 ; 5C Backslash
.byte 0x38,0x0C,0x0C,0x0C,0x0C,0x0C,0x38,0x00 ; 5D ]
.byte 0x10,0x28,0x44,0x00,0x00,0x00,0x00,0x00 ; 5E ^
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C ; 5F _
.byte 0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00 ; 60 `
.byte 0x00,0x00,0x38,0x0C,0x7C,0xCC,0x78,0x00 ; 61
.byte 0x20,0x60,0x7C,0x66,0x66,0x66,0x3C,0x00 ; 62
.byte 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00 ; 63
.byte 0x08,0x0C,0x7C,0xCC,0xCC,0xCC,0x78,0x00 ; 64
.byte 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00 ; 65
.byte 0x1C,0x36,0x30,0x38,0x30,0x30,0x10,0x00 ; 66
.byte 0x00,0x00,0x3C,0x66,0x66,0x3E,0x06,0x3C ; 67
.byte 0x20,0x60,0x6C,0x76,0x66,0x66,0x24,0x00 ; 68
.byte 0x18,0x00,0x18,0x18,0x18,0x18,0x08,0x00 ; 69
.byte 0x06,0x00,0x04,0x06,0x06,0x26,0x66,0x3C ; 6A
.byte 0x20,0x60,0x66,0x6C,0x78,0x6C,0x26,0x00 ; 6B
.byte 0x10,0x18,0x18,0x18,0x18,0x18,0x08,0x00 ; 6C
.byte 0x00,0x00,0x6C,0xFE,0xD6,0xD6,0xC6,0x00 ; 6D
.byte 0x00,0x00,0x3C,0x66,0x66,0x66,0x24,0x00 ; 6E
.byte 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00 ; 6F
.byte 0x00,0x00,0x3C,0x66,0x66,0x7C,0x60,0x20 ; 70
.byte 0x00,0x00,0x78,0xCC,0xCC,0x7C,0x0C,0x08 ; 71
.byte 0x00,0x00,0x38,0x7C,0x60,0x60,0x20,0x00 ; 72
.byte 0x00,0x00,0x3C,0x60,0x3C,0x06,0x7C,0x00 ; 73
.byte 0x10,0x30,0x3C,0x30,0x30,0x3E,0x1C,0x00 ; 74
.byte 0x00,0x00,0x24,0x66,0x66,0x66,0x3C,0x00 ; 75
.byte 0x00,0x00,0x24,0x66,0x66,0x3C,0x18,0x00 ; 76
.byte 0x00,0x00,0x44,0xD6,0xD6,0xFE,0x6C,0x00 ; 77
.byte 0x00,0x00,0xC6,0x6C,0x38,0x6C,0xC6,0x00 ; 78
.byte 0x00,0x00,0x24,0x66,0x66,0x3E,0x06,0x7C ; 79
.byte 0x00,0x00,0x7E,0x0C,0x18,0x30,0x7E,0x00 ; 7A
.byte 0x10,0x20,0x20,0x40,0x40,0x20,0x20,0x10 ; 7B {
.byte 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10 ; 7C |
.byte 0x08,0x04,0x04,0x02,0x02,0x04,0x04,0x08 ; 7D }
.byte 0x00,0x00,0x00,0x20,0x52,0x0C,0x00,0x00 ; 7E ~
.byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ; 7F
.byte 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ; 80
- Output:
Picture of output on VisualBoyAdvance screen
Arturo
loop 32..127 'num [
k: ø
case [num]
when? [=32] -> k: "␠"
when? [=127] -> k: "␡"
else -> k: to :string to :char num
prints pad ~"|num|: |k|" 10
if 1 = num%6 -> print ""
]
- Output:
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: ␡
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
- 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
# syntax: GAWK -f SHOW_ASCII_TABLE.AWK
# syntax: MAWK -f SHOW_ASCII_TABLE.AWK
BEGIN {
for (i=0; i<16; i++) {
for (j=32+i; j<128; j+=16) {
if (j == 32) { x = "SPC" }
else if (j == 127) { x = "DEL" }
else { x = sprintf("%c",j) }
printf("%3d: %-5s",j,x)
}
print ""
}
}
- 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
BASIC
BASIC256
for i = 32 to 47
for j = i to i + 80 step 16
begin case
case j = 32
s$ = "Spc"
case j = 127
s$ = "Del"
else
s$ = chr(j)
end case
print rjust(" "+string(j),5); ": "; ljust(s$,3);
next j
print
next i
Chipmunk Basic
10 cls
20 for r = 0 to 15
30 for c = 1 to 6
40 a = 16+r+c*16
50 print right$(" "+str$(a),4)": " chr$(a)tab (10*c);
60 next c
70 print
80 next r
- 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: ⌂
GW-BASIC
10 DEFINT I,J: DEFSTR S: DIM S(2)
20 S(0)="* "
30 S(1)="Spc"
40 S(2)="Del"
50 FOR I=32 TO 47
60 FOR J=I TO 127 STEP 16
70 MID$(S(0),1,1) = CHR$(J)
80 PRINT USING "###: \ \ ";J;S(-(J=32)-2*(J=127));
90 NEXT J
100 PRINT
110 NEXT I
- 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
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
MSX Basic
The GW-BASIC solution works without any changes.
QBasic
The QB64 solution works without any changes.
Run BASIC
for i = 32 to 47
for j = i to i + 80 step 16
select case j
case 32
s$ = "Spc"
case 127
s$ = "Del"
case else
s$ = chr$(j)
end select
print right$(" "+str$(j),4); ": "; s$; space$(3);
next j
print
next i
True BASIC
FOR i = 32 TO 47
FOR j = i TO i+80 STEP 16
SELECT CASE j
CASE 32
LET s$ = "Spc"
CASE 127
LET s$ = "Del"
CASE else
LET s$ = CHR$(j)
END SELECT
PRINT USING "###: ### ": j, s$;
NEXT j
PRINT
NEXT
- Output:
Same as QB64 entry.
XBasic
PROGRAM "ASCII table"
VERSION "0.0000"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
FOR i = 32 TO 47
FOR j = i TO i + 80 STEP 16
SELECT CASE j
CASE 32
s$ = "Spc"
CASE 127
s$ = "Del"
CASE ELSE
s$ = CHR$(j)
END SELECT
PRINT RJUST$(" "+STRING(j),4); ": "; LJUST$(s$,3);
NEXT j
PRINT
NEXT i
END FUNCTION
END PROGRAM
Yabasic
for i = 32 to 47
for j = i to i + 80 step 16
s$ = chr$(j)
if j = 32 s$ = "Spc"
if j = 127 s$ = "Del"
print str$(j, "#####"), ": ", s$;
next j
print
next i
BaCon
FOR j = 0 TO 15
FOR i = 32+j TO 127 STEP 16
PRINT i FORMAT " %3d - ";
SELECT i
CASE 32
PRINT "Spc";
CASE 127
PRINT "Del";
DEFAULT
PRINT i FORMAT "%c "
ENDSELECT
NEXT
PRINT
NEXT
- 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
BCPL
get "libhdr"
let str(n) =
n=32 -> "%I3: Spc ",
n=127 -> "%I3: Del ",
"%I3: %C "
let start() be
for i=32 to 47 do
$( for j=i to 127 by 16 do
writef(str(j), j, j)
wrch('*N')
$)
- 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
BQN
The final result is a 2D array of characters which is output line by line with •Out
.
chs←⟨"SPC"⟩∾(@+33+↕94)∾⟨"DEL"⟩
J←{𝕨∾' '∾𝕩}´
_pad←{(𝕗×·⌈´≠¨)⊸(↑¨)}
•Out˘J˘J¨⍉6‿16⥊<˘⍉(∾⟜':'¨¯1 _pad •Fmt¨32+↕96)≍1 _pad chs
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
Brainf***
> ++++++ ; 6 rows
> ++++ ++++ ++++ ++++ ; 16 columns
> ++++ ++++ ++++ ++++ ++++ ++++ ++++ ++++ ; 32: the starting character
<< ; move to row counter
[
> ; move to the column counter
[> ; move to character
. ; print it
+ ; increase it
<- ; decrease the column counter
]
+++++ +++++.[-] ; print newline
++++ ++++ ++++ ++++ ; set column counter again
<-] ; decrease row counter and loop
- Output:
!"#$%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~?
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;
}
- 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++
#include <string>
#include <iomanip>
#include <iostream>
inline constexpr auto HEIGHT = 16;
inline constexpr auto WIDTH = 6;
inline constexpr auto ASCII_START = 32;
// ASCII special characters
inline constexpr auto SPACE = 32;
inline constexpr auto DELETE = 127;
std::string displayAscii(char ascii) {
switch (ascii) {
case SPACE: return "Spc";
case DELETE: return "Del";
default: return std::string(1, ascii);
}
}
int main() {
for (std::size_t row = 0; row < HEIGHT; ++row) {
for (std::size_t col = 0; col < WIDTH; ++col) {
const auto ascii = ASCII_START + row + col * HEIGHT;
std::cout << std::right << std::setw(3) << ascii << " : " << std::left << std::setw(6) << displayAscii(ascii);
}
std::cout << '\n';
}
}
- 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#
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 + "";
}
}
- 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
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
- 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.
(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)))
- 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.
(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)))
- 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
CLU
ascii = proc (n: int) returns (string)
if n=32 then return("Spc")
elseif n=127 then return("Del")
else return(string$c2s(char$i2c(n)))
end
end ascii
start_up = proc ()
po: stream := stream$primary_output()
for i: int in int$from_to(32, 47) do
for j: int in int$from_to_by(i, 127, 16) do
stream$putright(po, int$unparse(j), 3)
stream$puts(po, ": ")
stream$putleft(po, ascii(j), 5)
end
stream$putl(po, "")
end
end start_up
- 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
COBOL
Uses free form syntax.
IDENTIFICATION DIVISION.
PROGRAM-ID. CHARSET.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CHARCODE PIC 9(3) VALUE 32.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
PERFORM UNTIL CHARCODE=128
DISPLAY FUNCTION CONCATENATE(
FUNCTION CONCATENATE(
CHARCODE,
" : "
),
FUNCTION CONCATENATE(
FUNCTION CHAR(CHARCODE),
" "
)
)
WITH NO ADVANCING
ADD 1 TO CHARCODE
END-PERFORM.
END PROGRAM CHARSET.
- Output:
032 : 033 : 034 : ! 035 : " 036 : # 037 : $ 038 : % 039 : & 040 : ' 041 : ( 042 : ) 043 : * 044 : + 045 : , 046 : - 047 : . 048 : / 049 : 0 050 : 1 051 : 2 052 : 3 053 : 4 054 : 5 055 : 6 056 : 7 057 : 8 058 : 9 059 : : 060 : ; 061 : < 062 : = 063 : > 064 : ? 065 : @ 066 : A 067 : B 068 : C 069 : D 070 : E 071 : F 072 : G 073 : H 074 : I 075 : J 076 : K 077 : L 078 : M 079 : N 080 : O 081 : P 082 : Q 083 : R 084 : S 085 : T 086 : U 087 : V 088 : W 089 : X 090 : Y 091 : Z 092 : [ 093 : \ 094 : ] 095 : ^ 096 : _ 097 : ` 098 : a 099 : b 100 : c 101 : d 102 : e 103 : f 104 : g 105 : h 106 : i 107 : j 108 : k 109 : l 110 : m 111 : n 112 : o 113 : p 114 : q 115 : r 116 : s 117 : t 118 : u 119 : v 120 : w 121 : x 122 : y 123 : z 124 : { 125 : | 126 : } 127 : ~
Commodore BASIC
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
- Output:
Common 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))
- 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
Cowgol
include "cowgol.coh";
# Print number with preceding space if <100 and trailing colon
sub print_num(n: uint8) is
if n < 100 then print_char(' '); end if;
print_i8(n);
print(": ");
end sub;
# Print character / Spc / Del padded to 5 spaces
sub print_ch(c: uint8) is
if c == ' ' then print("Spc ");
elseif c == 127 then print("Del ");
else
print_char(c);
print(" ");
end if;
end sub;
var c: uint8 := 32;
loop
print_num(c);
print_ch(c);
if c == 127 then
break;
end if;
c := c + 16;
if c > 127 then
print_nl();
c := c - 95;
end if;
end loop;
print_nl();
- 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
D
import std.stdio;
void main() {
for (int i = 0; i < 16; ++i) {
for (int j = 32 + i; j < 128; j += 16) {
switch (j) {
case 32:
writef("%3d : Spc ", j);
break;
case 127:
writef("%3d : Del ", j);
break;
default:
writef("%3d : %-3s ", j, cast(char)j);
break;
}
}
writeln;
}
}
- 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
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
- 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
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.
- 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
Draco
proc write_item(byte n) void:
*char chrstr = "* ";
chrstr* := pretend(n, char);
write(n:3, " : ",
case n
incase 32: "Spc "
incase 127: "Del "
default: chrstr
esac)
corp
proc main() void:
byte row, col;
for row from 32 upto 47 do
for col from row by 16 upto 127 do
write_item(col)
od;
writeln()
od
corp
- 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
EasyLang
numfmt 0 3
for i range0 16
for j = 32 + i step 16 to 127
if j = 32
x$ = "Spc"
elif j = 127
x$ = "Del"
else
x$ = strchar j & " "
.
write j & ": " & x$
.
print ""
.
Ecstasy
module ShowAsciiTable {
@Inject Console console;
void run() {
for (Int offset : 0..<16) {
for (Int ascii = 32+offset; ascii < 128; ascii += 16) {
console.print($|{ascii.toString().rightJustify(3)}/\
|{ascii.toByte().toByteArray()}: \
|{new Char(ascii).quoted().leftJustify(5)}
, suppressNewline=True);
}
console.print();
}
}
}
- Output:
32/0x20: ' ' 48/0x30: '0' 64/0x40: '@' 80/0x50: 'P' 96/0x60: '`' 112/0x70: 'p' 33/0x21: '!' 49/0x31: '1' 65/0x41: 'A' 81/0x51: 'Q' 97/0x61: 'a' 113/0x71: 'q' 34/0x22: '\"' 50/0x32: '2' 66/0x42: 'B' 82/0x52: 'R' 98/0x62: 'b' 114/0x72: 'r' 35/0x23: '#' 51/0x33: '3' 67/0x43: 'C' 83/0x53: 'S' 99/0x63: 'c' 115/0x73: 's' 36/0x24: '$' 52/0x34: '4' 68/0x44: 'D' 84/0x54: 'T' 100/0x64: 'd' 116/0x74: 't' 37/0x25: '%' 53/0x35: '5' 69/0x45: 'E' 85/0x55: 'U' 101/0x65: 'e' 117/0x75: 'u' 38/0x26: '&' 54/0x36: '6' 70/0x46: 'F' 86/0x56: 'V' 102/0x66: 'f' 118/0x76: 'v' 39/0x27: '\'' 55/0x37: '7' 71/0x47: 'G' 87/0x57: 'W' 103/0x67: 'g' 119/0x77: 'w' 40/0x28: '(' 56/0x38: '8' 72/0x48: 'H' 88/0x58: 'X' 104/0x68: 'h' 120/0x78: 'x' 41/0x29: ')' 57/0x39: '9' 73/0x49: 'I' 89/0x59: 'Y' 105/0x69: 'i' 121/0x79: 'y' 42/0x2A: '*' 58/0x3A: ':' 74/0x4A: 'J' 90/0x5A: 'Z' 106/0x6A: 'j' 122/0x7A: 'z' 43/0x2B: '+' 59/0x3B: ';' 75/0x4B: 'K' 91/0x5B: '[' 107/0x6B: 'k' 123/0x7B: '{' 44/0x2C: ',' 60/0x3C: '<' 76/0x4C: 'L' 92/0x5C: '\\' 108/0x6C: 'l' 124/0x7C: '|' 45/0x2D: '-' 61/0x3D: '=' 77/0x4D: 'M' 93/0x5D: ']' 109/0x6D: 'm' 125/0x7D: '}' 46/0x2E: '.' 62/0x3E: '>' 78/0x4E: 'N' 94/0x5E: '^' 110/0x6E: 'n' 126/0x7E: '~' 47/0x2F: '/' 63/0x3F: '?' 79/0x4F: 'O' 95/0x5F: '_' 111/0x6F: 'o' 127/0x7F: '\d'
Excel
LAMBDA
Binding the name asciiTable to the following lambda expression in the Name Manager of the Excel WorkBook:
(See LAMBDA: The ultimate Excel worksheet function)
asciiTable
=LAMBDA(i,
justifyRight(3)(" ")(i) & ": " & (
justifyRight(
3
)(" ")(
IF(32 = i,
"Spc",
IF(127 = i,
"Del",
CHAR(i)
)
)
)
)
)(
SEQUENCE(16, 6, 32, 1)
)
and also assuming the following generic binding in the Name Manager for the WorkBook:
justifyRight
=LAMBDA(n,
LAMBDA(c,
LAMBDA(s,
LET(
lng, LEN(s),
IF(
lng < n,
MID(
REPT(c, n),
lng, n - lng
) & s,
s
)
)
)
)
)
- Output:
The formula in cell B2 defines an array which populates the whole B2:G17 range.
(Justification within the cells depends on applying a monospaced font in Excel).
fx | =asciiTable | |||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | ||
1 | Ascii Table | |||||||
2 | 32: Spc | 33: ! | 34: " | 35: # | 36: $ | 37: % | ||
3 | 38: & | 39: ' | 40: ( | 41: ) | 42: * | 43: + | ||
4 | 44: , | 45: - | 46: . | 47: / | 48: 0 | 49: 1 | ||
5 | 50: 2 | 51: 3 | 52: 4 | 53: 5 | 54: 6 | 55: 7 | ||
6 | 56: 8 | 57: 9 | 58: : | 59: ; | 60: < | 61: = | ||
7 | 62: > | 63: ? | 64: @ | 65: A | 66: B | 67: C | ||
8 | 68: D | 69: E | 70: F | 71: G | 72: H | 73: I | ||
9 | 74: J | 75: K | 76: L | 77: M | 78: N | 79: O | ||
10 | 80: P | 81: Q | 82: R | 83: S | 84: T | 85: U | ||
11 | 86: V | 87: W | 88: X | 89: Y | 90: Z | 91: [ | ||
12 | 92: \ | 93: ] | 94: ^ | 95: _ | 96: ` | 97: a | ||
13 | 98: b | 99: c | 100: d | 101: e | 102: f | 103: g | ||
14 | 104: h | 105: i | 106: j | 107: k | 108: l | 109: m | ||
15 | 110: n | 111: o | 112: p | 113: q | 114: r | 115: s | ||
16 | 116: t | 117: u | 118: v | 119: w | 120: x | 121: y | ||
17 | 122: z | 123: { | 125: } | 126: ~ | 127: Del |
Or, separating code and character into adjacent Excel cells:
asciiTable2
=LAMBDA(i,
IF(0 <> MOD(i, 1),
LET(
code, FLOOR.MATH(i),
IF(32 = code,
"Spc",
IF(127 = code,
"Del",
CHAR(code)
)
)
),
i
)
)(
SEQUENCE(16, 12, 32, 0.5)
)
- Output:
The formula in cell B2 defines an array which populates the whole B2:M17 range:
fx | =asciiTable2 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | ||
1 | Ascii table | |||||||||||||
2 | 32 | Spc | 33 | ! | 34 | " | 35 | # | 36 | $ | 37 | % | ||
3 | 38 | & | 39 | ' | 40 | ( | 41 | ) | 42 | * | 43 | + | ||
4 | 44 | , | 45 | - | 46 | . | 47 | / | 48 | 0 | 49 | 1 | ||
5 | 50 | 2 | 51 | 3 | 52 | 4 | 53 | 5 | 54 | 6 | 55 | 7 | ||
6 | 56 | 8 | 57 | 9 | 58 | : | 59 | ; | 60 | < | 61 | = | ||
7 | 62 | > | 63 | ? | 64 | @ | 65 | A | 66 | B | 67 | C | ||
8 | 68 | D | 69 | E | 70 | F | 71 | G | 72 | H | 73 | I | ||
9 | 74 | J | 75 | K | 76 | L | 77 | M | 78 | N | 79 | O | ||
10 | 80 | P | 81 | Q | 82 | R | 83 | S | 84 | T | 85 | U | ||
11 | 86 | V | 87 | W | 88 | X | 89 | Y | 90 | Z | 91 | [ | ||
12 | 92 | \ | 93 | ] | 94 | ^ | 95 | _ | 96 | ` | 97 | a | ||
13 | 98 | b | 99 | c | 100 | d | 101 | e | 102 | f | 103 | g | ||
14 | 104 | h | 105 | i | 106 | j | 107 | k | 108 | l | 109 | m | ||
15 | 110 | n | 111 | o | 112 | p | 113 | q | 114 | r | 115 | s | ||
16 | 116 | t | 117 | u | 118 | v | 119 | w | 120 | x | 121 | y | ||
17 | 122 | z | 123 | { | 124 | | | 125 | } | 126 | ~ | 127 | Del |
Factor
Idiomatic version
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
Go translation
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
- 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.
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 ;
Test Output at the console
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
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.
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
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
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
- 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
// 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.
- 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 :
Frink
a = ["32 Space"]
for i = 33 to 126
a.push["$i " + char[i]]
a.push["127 Delete"]
println[formatTableBoxed[columnize[a,8].transpose[], "left"]]
- Output:
┌────────┬────┬────┬────┬────┬────┬────┬────┬─────┬─────┬─────┬──────────┐ │32 Space│40 (│48 0│56 8│64 @│72 H│80 P│88 X│96 ` │104 h│112 p│120 x │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │33 ! │41 )│49 1│57 9│65 A│73 I│81 Q│89 Y│97 a │105 i│113 q│121 y │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │34 " │42 *│50 2│58 :│66 B│74 J│82 R│90 Z│98 b │106 j│114 r│122 z │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │35 # │43 +│51 3│59 ;│67 C│75 K│83 S│91 [│99 c │107 k│115 s│123 { │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │36 $ │44 ,│52 4│60 <│68 D│76 L│84 T│92 \│100 d│108 l│116 t│124 | │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │37 % │45 -│53 5│61 =│69 E│77 M│85 U│93 ]│101 e│109 m│117 u│125 } │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │38 & │46 .│54 6│62 >│70 F│78 N│86 V│94 ^│102 f│110 n│118 v│126 ~ │ ├────────┼────┼────┼────┼────┼────┼────┼────┼─────┼─────┼─────┼──────────┤ │39 ' │47 /│55 7│63 ?│71 G│79 O│87 W│95 _│103 g│111 o│119 w│127 Delete│ └────────┴────┴────┴────┴────┴────┴────┴────┴─────┴─────┴─────┴──────────┘
Fōrmulæ
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation —i.e. XML, JSON— they are intended for storage and transfer purposes more than visualization and edition.
Programs in Fōrmulæ are created/edited online in its website.
In this page you can see and run the program(s) related to this task and their results. You can also change either the programs or the parameters they are called with, for experimentation, but remember that these programs were created with the main purpose of showing a clear solution of the task, and they generally lack any kind of validation.
Solution
FutureBasic
include "NSLog.incl"
local fn ASCIITable as CFStringRef
NSinteger i
CFStringRef temp
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
for i = 32 to 127
temp = fn StringWithFormat( @"%c", i )
if i == 32 then temp = @"Spc"
if i == 127 then temp = @"Del"
MutableStringAppendString( mutStr, fn StringWithFormat( @"%-1d : %@\n", i, temp ) )
next
CFArrayRef colArr = fn StringComponentsSeparatedByString( mutStr, @"\n" )
MutableStringSetString( mutStr, @"" )
for i = 0 to 15
ObjectRef col0 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i ) )
ObjectRef col1 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 16 ) )
ObjectRef col2 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 32 ) )
ObjectRef col3 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 48 ) )
ObjectRef col4 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 64 ) )
ObjectRef col5 = fn StringUTF8String( fn ArrayObjectAtIndex( colArr, i + 80 ) )
MutableStringAppendString( mutStr, fn StringWithFormat( @"%-10s %-10s %-10s %-10s %-10s %-10s\n", col0, col1, col2, col3, col4, col5 ) )
next
end fn = fn StringWithString( mutStr )
NSLog( @"%@", fn ASCIITable )
HandleEvents
- Output:
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p 33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q 34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r 35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s 36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t 37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u 38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v 39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w 40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x 41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y 42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z 43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : { 44 : , 60 : < 76 : L 92 : \ 108 : l 124 : | 45 : - 61 : = 77 : M 93 : ] 109 : m 125 : } 46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~ 47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Go
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()
}
}
- 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
Groovy
class ShowAsciiTable {
static void main(String[] args) {
for (int i = 32; i <= 127; i++) {
if (i == 32 || i == 127) {
String s = i == 32 ? "Spc" : "Del"
printf("%3d: %s ", i, s)
} else {
printf("%3d: %c ", i, i)
}
if ((i - 1) % 6 == 0) {
println()
}
}
}
}
- 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
Haskell
import Data.Char (chr)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import Text.Printf (printf)
----------------------- ASCII TABLE ----------------------
asciiTable :: String
asciiTable =
unlines $
(printf "%-12s" =<<)
<$> transpose
(chunksOf 16 $ asciiEntry <$> [32 .. 127])
asciiEntry :: Int -> String
asciiEntry n
| null k = k
| otherwise = concat [printf "%3d" n, " : ", k]
where
k = asciiName n
asciiName :: Int -> String
asciiName n
| 32 > n = []
| 127 < n = []
| 32 == n = "Spc"
| 127 == n = "Del"
| otherwise = [chr n]
--------------------------- TEST -------------------------
main :: IO ()
main = putStrLn asciiTable
- 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
Insitux
(-> (for i (range 16)
j (range (+ i 32) 128 16)
(let k (match j 32 "Spc" 127 "Del" (str (char-code j) " ")))
(strn ((< j 100) " ") j " : " k))
(partition 6)
(map (join " "))
(join "\n"))
- 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
J
;"1 (_9{.":,': ',ucp)each 32+|:i.6 16 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: ?
Note that ascii 127 does not have a standard representation, so its appearance will depend on a variety of issues.
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();
}
}
}
}
- 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
You could also do this:
String printASCIITable() {
StringBuilder string = new StringBuilder();
String newline = System.lineSeparator();
string.append("dec hex binary oct char").append(newline);
for (int decimal = 32; decimal <= 127; decimal++) {
string.append(format(decimal));
switch (decimal) {
case 32 -> string.append("[SPACE]");
case 127 -> string.append("[DELETE]");
default -> string.append((char) decimal);
}
string.append(newline);
}
return string.toString();
}
String format(int value) {
return "%-3d %01$-2x %7s %01$-3o ".formatted(value, Integer.toBinaryString(value));
}
dec hex binary oct char 32 20 100000 40 [SPACE] 33 21 100001 41 ! 34 22 100010 42 " 35 23 100011 43 # 36 24 100100 44 $ 37 25 100101 45 % 38 26 100110 46 & 39 27 100111 47 ' 40 28 101000 50 ( 41 29 101001 51 ) 42 2a 101010 52 * 43 2b 101011 53 + 44 2c 101100 54 , 45 2d 101101 55 - 46 2e 101110 56 . 47 2f 101111 57 / 48 30 110000 60 0 49 31 110001 61 1 50 32 110010 62 2 51 33 110011 63 3 52 34 110100 64 4 53 35 110101 65 5 54 36 110110 66 6 55 37 110111 67 7 56 38 111000 70 8 57 39 111001 71 9 58 3a 111010 72 : 59 3b 111011 73 ; 60 3c 111100 74 < 61 3d 111101 75 = 62 3e 111110 76 > 63 3f 111111 77 ? 64 40 1000000 100 @ 65 41 1000001 101 A 66 42 1000010 102 B 67 43 1000011 103 C 68 44 1000100 104 D 69 45 1000101 105 E 70 46 1000110 106 F 71 47 1000111 107 G 72 48 1001000 110 H 73 49 1001001 111 I 74 4a 1001010 112 J 75 4b 1001011 113 K 76 4c 1001100 114 L 77 4d 1001101 115 M 78 4e 1001110 116 N 79 4f 1001111 117 O 80 50 1010000 120 P 81 51 1010001 121 Q 82 52 1010010 122 R 83 53 1010011 123 S 84 54 1010100 124 T 85 55 1010101 125 U 86 56 1010110 126 V 87 57 1010111 127 W 88 58 1011000 130 X 89 59 1011001 131 Y 90 5a 1011010 132 Z 91 5b 1011011 133 [ 92 5c 1011100 134 \ 93 5d 1011101 135 ] 94 5e 1011110 136 ^ 95 5f 1011111 137 _ 96 60 1100000 140 ` 97 61 1100001 141 a 98 62 1100010 142 b 99 63 1100011 143 c 100 64 1100100 144 d 101 65 1100101 145 e 102 66 1100110 146 f 103 67 1100111 147 g 104 68 1101000 150 h 105 69 1101001 151 i 106 6a 1101010 152 j 107 6b 1101011 153 k 108 6c 1101100 154 l 109 6d 1101101 155 m 110 6e 1101110 156 n 111 6f 1101111 157 o 112 70 1110000 160 p 113 71 1110001 161 q 114 72 1110010 162 r 115 73 1110011 163 s 116 74 1110100 164 t 117 75 1110101 165 u 118 76 1110110 166 v 119 77 1110111 167 w 120 78 1111000 170 x 121 79 1111001 171 y 122 7a 1111010 172 z 123 7b 1111011 173 { 124 7c 1111100 174 | 125 7d 1111101 175 } 126 7e 1111110 176 ~ 127 7f 1111111 177 [DELETE]
JavaScript
(() => {
"use strict";
// ------------------- ASCII TABLE -------------------
// asciiTable :: String
const asciiTable = () =>
transpose(
chunksOf(16)(
enumFromTo(32)(127)
.map(asciiEntry)
)
)
.map(
xs => xs.map(justifyLeft(12)(" "))
.join("")
)
.join("\n");
// 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 ----------------
// chr :: Int -> Char
const chr = x =>
// The character at unix code-point x.
String.fromCodePoint(x);
// chunksOf :: Int -> [a] -> [[a]]
const chunksOf = n => {
// xs split into sublists of length n.
// The last sublist will be short if n
// does not evenly divide the length of xs .
const go = xs => {
const chunk = xs.slice(0, n);
return 0 < chunk.length ? (
[chunk].concat(
go(xs.slice(n))
)
) : [];
};
return go;
};
// enumFromTo :: Int -> Int -> [Int]
const enumFromTo = m =>
n => Array.from({
length: 1 + n - m
}, (_, i) => m + i);
// justifyLeft :: Int -> Char -> String -> String
const justifyLeft = n =>
// The string s, followed by enough padding (with
// the character c) to reach the string length n.
c => s => n > s.length ? (
s.padEnd(n, c)
) : s;
// justifyRight :: Int -> Char -> String -> String
const justifyRight = n =>
// The string s, preceded by enough padding (with
// the character c) to reach the string length n.
c => s => Boolean(s) ? (
s.padStart(n, c)
) : "";
// transpose :: [[a]] -> [[a]]
const transpose = rows =>
// The columns of the input transposed
// into new rows.
// This version assumes input rows of even length.
0 < rows.length ? rows[0].map(
(x, i) => rows.flatMap(
v => v[i]
)
) : [];
// MAIN ---
return asciiTable();
})();
- 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
#!/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!=
*/
- 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
jq
Works with gojq, the Go implementation of jq
The following program generalizes the task to produce a table for wide stretches of Unicode characters, not just 32 .. 127. In addition, the functions for producing both row-wise and column-wise tables are provided and illustrated.
# Pretty printing
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
def table($ncols; $colwidth):
nwise($ncols) | map(lpad($colwidth)) | join(" ");
# transposed table
def ttable($rows):
[nwise($rows)] | transpose[] | join(" ");
# Representation of control characters, etc
def humanize:
def special:
{ "0": "NUL", "7": "BEL", "8": "BKS",
"9": "TAB", "10": "LF ", "13": "CR ",
"27": "ESC", "127": "DEL", "155": "CSI" };
if . < 32 or . == 127 or . == 155
then (special[tostring] // "^" + ([64+.]|implode))
elif . > 127 and . < 160 then "\\\(.+72|tostring)"
else [.] | implode
end
| lpad(4) ;
Base Task
# produce a flat array
def prepare($m;$n):
[range($m; $n) | "\(lpad(7)): \(humanize)" ];
# Row-wise presentation of 32 through 127 in 6 columns
prepare(32;128) | table(6; 10)
# Column-wise with 16 rows would be produced by:
# prepare(32;128) | ttable(16)
- Output:
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
Column-wise table of 128..255
# Column-wise representation with 16 rows
(prepare(128;256) | ttable(16))
- Output:
128: \200 144: \216 160: 176: ° 192: À 208: Ð 224: à 240: ð 129: \201 145: \217 161: ¡ 177: ± 193: Á 209: Ñ 225: á 241: ñ 130: \202 146: \218 162: ¢ 178: ² 194: Â 210: Ò 226: â 242: ò 131: \203 147: \219 163: £ 179: ³ 195: Ã 211: Ó 227: ã 243: ó 132: \204 148: \220 164: ¤ 180: ´ 196: Ä 212: Ô 228: ä 244: ô 133: \205 149: \221 165: ¥ 181: µ 197: Å 213: Õ 229: å 245: õ 134: \206 150: \222 166: ¦ 182: ¶ 198: Æ 214: Ö 230: æ 246: ö 135: \207 151: \223 167: § 183: · 199: Ç 215: × 231: ç 247: ÷ 136: \208 152: \224 168: ¨ 184: ¸ 200: È 216: Ø 232: è 248: ø 137: \209 153: \225 169: © 185: ¹ 201: É 217: Ù 233: é 249: ù 138: \210 154: \226 170: ª 186: º 202: Ê 218: Ú 234: ê 250: ú 139: \211 155: CSI 171: « 187: » 203: Ë 219: Û 235: ë 251: û 140: \212 156: \228 172: ¬ 188: ¼ 204: Ì 220: Ü 236: ì 252: ü 141: \213 157: \229 173: 189: ½ 205: Í 221: Ý 237: í 253: ý 142: \214 158: \230 174: ® 190: ¾ 206: Î 222: Þ 238: î 254: þ 143: \215 159: \231 175: ¯ 191: ¿ 207: Ï 223: ß 239: ï 255: ÿ
Julia
Base Task
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
- 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.
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
- 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:
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")
- 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.
#= 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
Using these is simple, only provide the data, and prt it.
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
K
`0:"\n"/" "/'+6 16#{-6$($x),-2$`c$x}'32+!96
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
Kotlin
// 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()
}
}
- 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
Lambdatalk
{def format
{lambda {:i :c}
{if {< :i 100}
then {span {@ style="color:white;"}.}:i : :c
else :i : :c}}}
-> format
{S.map
{lambda {:i}
{div}
{S.map {lambda {:i}
{if {= :i 32} then {format :i {span {@ style="color:#fff;"}.}}
else {if {= :i 123} then {format :i left brace}
else {if {= :i 125} then {format :i right brace}
else {if {= :i 127} then {format :i del}
else {format :i {code2char :i}}}}}}}
{S.serie {+ 32 :i} 127 16}}}
{S.serie 0 15}}
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 : left brace
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : right brace
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : del
Lang
$i
repeat($[i], 16) {
$j $= $i + 32
while($j < 128) {
if($j == 32) {
$val = SPC
}elif($j == 127) {
$val = DEL
}else {
$val = fn.char($j)
}
fn.printf(%4d : %-3s, $j, $val)
$j += 16
}
fn.println()
}
- 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
for i of 16 {
for j = 31 + i ; j < 128 ; j += 16 {
val L = switch(j; 32: "spc"; 127: "del"; cp2s(j))
write "{{j:3}} : {{L:-4}}"
}
writeln()
}
- 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
Locomotive Basic
10 mode 1:defint a-z
20 for x=1 to 6
30 for y=1 to 16
40 n=16*(x-1)+y+31
50 locate 6*(x-1)+1,y
60 print using "###";n;
70 print " ";chr$(n);
80 next
90 next
- 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 🮕
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
- 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
Addition: Show all Ascii from 0, using 0x2400 to 0x2420 unicode symbols.
Function ProduceAscii$ {
Document Ascii$="\"
DelUnicode$=ChrCode$(0x2421)
j=0
Print Ascii$;
For i=0 to 15
Print Hex$(i, .5);
Ascii$=Hex$(i, .5)
Next
For i=0 to 32
If pos>16 then
Ascii$={
}+Hex$(j, .5)
Print : Print Hex$(j, .5);: j++
End if
Print Chrcode$(i+0x2400);
Ascii$=Chrcode$(i+0x2400)
Next
For i=33 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$()
- Output:
\0123456789ABCDEF 0␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏ 1␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟ 2␠!"#$%&'()*+,-./ 30123456789:;<=>? 4@ABCDEFGHIJKLMNO 5PQRSTUVWXYZ[\]^_ 6`abcdefghijklmno 7pqrstuvwxyz{|}~␡
MACRO-11
.TITLE ASCTAB
.MCALL .PRINT,.EXIT
ASCTAB::MOV #40,R5
MOV #20,R4
1$: MOV #NBUF,R1
MOV R5,R2
2$: MOV #-1,R3
3$: INC R3
SUB #12,R2
BCC 3$
ADD #72,R2
MOVB R2,-(R1)
MOV R3,R2
BNE 2$
CMP R1,#NUM
BEQ 4$
MOVB #40,-(R1)
4$: .PRINT #NUM
CMP #40,R5
BEQ 5$
CMP #177,R5
BEQ 6$
MOVB R5,CHR
.PRINT #CHR
BR 7$
5$: .PRINT #SPC
BR 7$
6$: .PRINT #DEL
7$: ADD #20,R5
CMP R5,#200
BLT 1$
SUB #137,R5
.PRINT #NL
DEC R4
BNE 1$
.EXIT
NUM: .ASCII / /
NBUF: .ASCII /: /<200>
CHR: .ASCII /. /<200>
SPC: .ASCII /SPC /<200>
DEL: .ASCII /DEL /<200>
NL: .ASCIZ //
.END ASCTAB
- 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
Mathematica / Wolfram Language
StringRiffle[StringJoin@@@Transpose[Partition[ToString[#]<>": "<>Switch[#,32,"Spc ",127,"Del ",_,FromCharacterCode[#]<>" "]&/@Range[32,127],16]],"\n"]
- 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
Miranda
main :: [sys_message]
main = [Stdout table]
table :: [char]
table = lay [concat [item n | n<-[row, (row+16)..127]] | row<-[32..47]]
item :: num->[char]
item n = num ++ " : " ++ desc
where num = reverse (take 3 (reverse (shownum n) ++ repeat ' '))
desc = "Spc ", if n = 32
= "Del ", if n = 127
= decode n : " ", otherwise
- 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
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
- 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
Modula-2
MODULE AsciiTable;
FROM InOut IMPORT Write, WriteCard, WriteString, WriteLn;
VAR row, col: CARDINAL;
PROCEDURE WriteItem(n: CARDINAL);
BEGIN
WriteCard(n, 3);
WriteString(": ");
CASE n OF
32: WriteString("Spc ")
| 127: WriteString("Del ")
ELSE
Write(CHR(n));
WriteString(" ")
END
END WriteItem;
BEGIN
FOR row := 32 TO 47 DO
FOR col := row TO 127 BY 16 DO
WriteItem(col)
END;
WriteLn
END
END AsciiTable.
- 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
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
- 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
import strformat
for i in 0..15:
for j in countup(32 + i, 127, step = 16):
let k = case j
of 32: "Spc"
of 127: "Del"
else: $chr(j)
write(stdout, fmt"{j:3d} : {k:<6s}")
write(stdout, "\n")
- 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
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();
};
};
}
}
- 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
OCaml
let show_char i =
Printf.printf "%5u: %s" i (match i with 32 -> "SPC" | 127 -> "DEL"
| _ -> Printf.sprintf " %c " (char_of_int i))
let () =
for i = 32 to 47 do
for j = 0 to 5 do show_char (j lsl 4 + i) done |> print_newline
done
- 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
OxygenBasic
uses console
int i,j
string c
for i=32 to 127
select case i
case 32 : c="spc"
case 127: c="del"
case else c=chr i
end select
print i ": " c tab
j++
if j = 8 'columns
print cr
j=0
endif
next
pause
Perl
Output in the same style as Raku.
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) { '<nowiki>|</nowiki>' }
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<br>0x%02X<br><big><big title="%s">%s</big></big>\n],
$_, $_, charnames::viacode($_), glyph($_);
}
}
print qq[|}\n];
Phix
with javascript_semantics 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),"\x7F","del"))
- 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
<?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;
- 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 | +----------+----------+----------+----------+----------+----------+
PL/M
100H: /* SHOW AN ASCII TABLE FROM 32 TO 127 */
/* CP/M BDOS SYSTEM CALL */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
/* I/O ROUTINES */
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$BYTE: PROCEDURE( N );
DECLARE N BYTE;
DECLARE V BYTE;
V = N MOD 100;
CALL PR$CHAR( ' ' );
CALL PR$CHAR( '0' + ( N / 100 ) );
CALL PR$CHAR( '0' + ( V / 10 ) );
CALL PR$CHAR( '0' + ( V MOD 10 ) );
END PR$BYTE;
/* ASCII TABLE */
DECLARE ( A, C ) BYTE;
DO C = 32 TO 32 + 15;
DO A = C TO C + ( 16 * 5 ) BY 16;
CALL PR$BYTE( A );
CALL PR$STRING( .': $' );
IF A = 32 THEN CALL PR$STRING( .'SPC$' );
ELSE IF A = 127 THEN CALL PR$STRING( .'DEL$' );
ELSE DO;
CALL PR$CHAR( ' ' );
CALL PR$CHAR( A );
CALL PR$CHAR( ' ' );
END;
END;
CALL PR$STRING( .( 0DH, 0AH, '$' ) );
END;
EOF
- Output:
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
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).
- 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
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
- 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
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()
- 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:
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('<table border="3px" style="background-color:LightCyan;text-align:center">\n <tr>')
for n in range(128):
if n %16 == 0 and 1 < n:
print(" </tr><tr>")
print(f' <td style="center">{n}<br>0x{n:02x}<br><big><b title="{escape(name(pp(n)))}">{escape(pp(n))}</b></big></td>')
print(""" </tr>\n</table>""")
- 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:
'''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()
- 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
# 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]))
- 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
QB64
DIM s AS STRING
FOR i% = 32 TO 47
FOR j% = i% TO i% + 80 STEP 16
SELECT CASE j%
CASE 32
s$ = "Spc"
CASE 127
s$ = "Del"
CASE ELSE
s$ = CHR$(j%)
END SELECT
PRINT USING "###: \ \"; j%; s$;
NEXT j%
PRINT
NEXT i%
- 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
Quackery
[ dup 32 = iff
[ drop say 'spc' ] done
dup 127 = iff
[ drop say 'del' ] done
emit sp sp ] is echoascii ( n --> )
[ dup echo say ': '
dup echoascii
84 < 3 + times sp ] is echoelt ( n --> )
[ sp 81 times
[ dup i^ + echoelt 16 step ]
drop cr ] is echorow ( n --> )
[ 16 times [ i^ 32 + echorow ] ] is echotable ( --> )
echotable
- 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
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")
}
- 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
(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))
- 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.
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<br>0x%02X<br><big><big title="%s">%s</big></big>] ~ "\n",
$_, $_, .&glyph.uniname.subst('SYMBOL FOR ', ''),
.&glyph.subst('|', '<nowiki>|</nowiki>')) for @row;
}
say '|}';
- 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 ␡ |
Red
Red ["ASCII table"]
repeat i 16 [
repeat j 6 [
n: j - 1 * 16 + i + 31
prin append pad/left n 3 ": "
prin pad switch/default n [
32 ["spc"]
127 ["del"]
] [to-char n] 4
]
prin newline
]
- 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
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.
/*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
- 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
# 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()
}
Output:
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(" ")}
- 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
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!();
}
}
- 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).
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(" ")))
}
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;
- 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
SETL
program ascii_table;
loop for i in [32..47] do
print(+/[lpad(str j, 3) + ' : ' + rpad(ascii j, 6) : j in [i, i+16..127]]);
end loop;
op ascii(n);
return {[32, 'Spc'], [127, 'Del']}(n) ? (char n);
end op;
end program;
- 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
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
- 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
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) ;
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
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 ""
}
- 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
TXR
(let ((spcdel (relate " \x7f" #("Spc" "Del"))))
(each ((r 32..48))
(each ((c (take 6 (range r : 16))))
(put-string (pic "###: <<<" c [spcdel (chr-num c)])))
(put-line)))
- 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
VBA
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
- 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
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
- 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
V (Vlang)
fn main() {
for i in 0..16{
for j := 32 + i; j < 128; j += 16 {
mut k := u8(j).ascii_str()
match j {
32 {
k = "Spc"
}
127 {
k = "Del"
} else {
}
}
print("${j:3} : ${k:-3} ")
}
println('')
}
}
- 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
VTL-2
10 C=32
20 L=16
30 #=C>100*50
40 $=32
50 ?=C
60 ?=": ";
70 #=C=32*120
80 #=C=127*140
90 $=C
100 ?=" ";
110 #=150
120 ?="Spc ";
130 #=150
140 ?="Del ";
150 C=C+16
160 #=C<128*30
170 C=C-95
180 L=L-1
190 ?=""
200 #=L=0=0*30
- 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
Wren
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()
}
- 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
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);
];
]
- 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
Z80 Assembly
Use the /S8 switch on the ZSM4 assembler for 8 significant characters for labels and names
;
; Print ASCII table using Z80 assembly language
;
; Runs under CP/M 3.1 on YAZE-AG-2.51.2 Z80 emulator
; Assembled with zsm4 on same emulator/OS, uses macro capabilities of said assembler
; Created with vim under Windows
;
; Thanks to https://wikiti.brandonw.net for the idea for the conversion routine hl -> decimal ASCII
;
; 2023-04-04 Xorph
;
;
; Useful definitions
;
bdos equ 05h ; Call to CP/M BDOS function
strdel equ 6eh ; Set string delimiter
wrtstr equ 09h ; Write string to console
numrows equ 16d ; Number of rows for output
numcols equ 6d ; Number of columns for output
nul equ 00h ; ASCII control characters
esc equ 1bh
cr equ 0dh
lf equ 0ah
cnull equ '0' ; ASCII character constants
spc equ 20h
del equ 7fh
;
; Macros for BDOS calls
;
setdel macro char ; Set string delimiter to char
ld c,strdel
ld e,char
call bdos
endm
print macro msg ; Output string to console
ld c,wrtstr
ld de,msg
call bdos
endm
newline macro ; Print newline
ld c,wrtstr
ld de,crlf
call bdos
endm
pushall macro ; Save all registers to stack
push af
push bc
push de
push hl
push ix
push iy
endm
popall macro ; Recall all registers from stack
pop iy
pop ix
pop hl
pop de
pop bc
pop af
endm
;
; =====================
; Start of main program
; =====================
;
cseg
asciitab:
setdel nul ; Set string terminator to nul ('\0') - '$' is default in CP/M
ld a,spc ; First ASCII code to print
loop:
ld (char),a ; Put ASCII code in output placeholder
ld h,0 ; Register pair hl is used for printing the number, register h remains 0
ld l,a ; Put ASCII code in hl for decimal conversion
ld ix,buffer
call dispHL ; Create decimal representation
ld d,3d ; Pad decimal representation to 3 places with leading blanks
ld e,' ' ; Registers d and e are modified in macro, so assign each time
ld hl,buffer
ld bc,format
call padstrl
print format ; Print the whole thing
print colon
chkspc:
ld a,(char) ; Load again, register a was lost during BDOS calls
cp spc ; Check if Spc
jr nz,chkdel ; If not, check if Del
print txtspc ; If yes, print the text for Spc
jr nextcol ; ...and skip to the next column
chkdel:
ld a,(char) ; Load again, register a was lost during BDOS calls
cp del ; Check if Del
jr nz,printc ; If not, print normal char
print txtdel ; If yes, print the text for Del
jr nextcol ; ...and skip to the next column
printc:
print char ; Normal char
nextcol:
ld a,(curcol) ; Increase output column
inc a
cp numcols ; If last column, go to next row
jr z,nextrow
ld (curcol),a ; Save column counter
ld a,(char) ; Increase ASCII code by the number of rows for next column in same row
add a,numrows
jr loop ; Next code
nextrow:
newline ; Display next row
xor a ; Set column counter back to 0
ld (curcol),a
ld a,(currow) ; Increase row counter
inc a
cp numrows ; When last row has been finished, we are done
jr z,exitprg
ld (currow),a ; Save row counter
ld a,(char) ; Set ASCII code back to starting code of next row
sub a,numrows * (numcols - 1d) - 1d
jp loop ; Use jp instead of jr because of jump distance!
exitprg:
newline
ret ; Return to CP/M
;
; ===================
; End of main program
; ===================
;
;
; Helper routines - notice that the Z80 does not have a divide instruction
; Notice further that CP/M does not have any support for pretty-printing
; formatted numbers and stuff like that. So we have to do all this by hand...
;
;
; Converts the value (unsigned int) in register hl to its decimal representation
; Register ix has memory address of target for converted value
; String is terminated with nul character (\0)
;
dispHL:
pushall
ld b,1 ; Flag for leading '0'
irp x,<-10000,-1000,-100,-10,-1>
ld de,x ; Subtract powers of 10 and determine digit
call calcdig
endm
ld a,nul ; Terminate result string with nul
ld (ix+0),a
popall
ret ; End of conversion routine
calcdig:
ld a,cnull-1 ; Determine the digit character
incrdig:
inc a ; Start with '0'
add hl,de ; As long as subtraction is possible, increment digit character
jr c,incrdig
sbc hl,de ; If negative, undo last subtraction and continue with remainder
cp cnull ; Check for leading '0', these are ignored
jr nz,adddig
bit 0,b ; Use bit instruction for check if flag set, register a contains digit
ret nz ; If '0' found and flag set, it is a leading '0' and we return
adddig:
ld b,0 ; Reset flag for leading '0', we are now outputting digits
ld (ix+0),a ; Store character in memory and set ix to next location
inc ix
ret ; End of conversion helper routine
;
; Formats a string to the specified minimum width with the specified filler character
; Register hl has memory address of nul-terminated string
; Register bc has memory address of target for padded string
; Register d has width
; Register e has filler character/byte
; Padding is on the left (function is intended for padding integer numbers)
;
padstrl:
pushall
push hl ; Save address of source for copy later on
ld a,d ; Check if width is 0, just copy string if so
cp 0
jr z,copysrc
ld a,nul ; Search for end of string. Each non-nul character decrements d
findnul:
cp (hl)
jr z,nulfound ; Found end of string, d contains number of padding to add
dec d
jr z,copysrc
inc hl
jr findnul ; Repeat with next character
nulfound:
ld a,e ; Store as many padding characters to target as specified in register d
inspad:
ld (bc),a
inc bc ; Move to next memory address and decrease d
dec d
jr nz,inspad
copysrc:
pop hl ; Transfer source to target, bc points to first memory address after padding
movechar:
ld a,(hl)
ld (bc),a
inc hl
inc bc
cp nul ; Check if nul character copied
jr nz,movechar ; If no, repeat with next character
popall
ret ; End of padding routine
;
; ================
; Data definitions
; ================
;
dseg
crlf: defb cr,lf,nul ; Generic newline
buffer: defs 10 ; Buffer for conversion of number to text
format: defs 10 ; Formatted number for output
colon: defz ' : ' ; Separator number/character, nul-terminated
char: defz ' ' ; Placeholder for ASCII character, nul-terminated
txtspc: defz 'Spc ' ; Space character 20h
txtdel: defz 'Del ' ; Del character 7fh
currow: defb 0d ; Current row
curcol: defb 0d ; Current column
- 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
Zig
const print = @import("std").debug.print;
pub fn main() void {
var i: u8 = 33;
print(" 32: Spc", .{});
while (i < 127) : (i += 1) {
print("{:03}: {c} ", .{ i, i });
if (@mod(i, 6) == 1) {
print("\n", .{});
}
}
print("127: Del", .{});
}
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)
)
})
- 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.
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
- 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
- 11l
- 6502 Assembly
- 8080 Assembly
- 8086 Assembly
- Action!
- Ada
- ALGOL 68
- ALGOL W
- APL
- AppleScript
- Applesoft BASIC
- ARM Assembly
- Arturo
- AutoHotkey
- AWK
- BASIC
- BASIC256
- Chipmunk Basic
- GW-BASIC
- IS-BASIC
- MSX Basic
- QBasic
- Run BASIC
- True BASIC
- XBasic
- Yabasic
- BaCon
- BCPL
- BQN
- Brainf***
- C
- C++
- C sharp
- Caché ObjectScript
- Clojure
- CLU
- COBOL
- Commodore BASIC
- Pages with broken file links
- Common Lisp
- Cowgol
- D
- Dc
- Delphi
- Draco
- EasyLang
- Ecstasy
- Excel
- Factor
- Forth
- Fortran
- FreeBASIC
- Free Pascal
- Frink
- Fōrmulæ
- FutureBasic
- Go
- Groovy
- Haskell
- Insitux
- J
- Java
- JavaScript
- Jsish
- Jq
- Julia
- K
- Kotlin
- Lambdatalk
- Lang
- Langur
- Locomotive Basic
- Lua
- M2000 Interpreter
- MACRO-11
- Mathematica
- Wolfram Language
- Miranda
- MiniScript
- Modula-2
- Nanoquery
- Nim
- Objeck
- OCaml
- OxygenBasic
- Perl
- Phix
- Phix/basics
- PHP
- PL/M
- Prolog
- PureBasic
- Python
- QB64
- Quackery
- R
- Racket
- Raku
- Red
- REXX
- Ring
- Ruby
- Rust
- Scala
- Seed7
- SETL
- Spin
- Standard ML
- Tcl
- TXR
- VBA
- Visual Basic .NET
- V (Vlang)
- VTL-2
- Wren
- Wren-fmt
- XPL0
- Z80 Assembly
- Zig
- Zkl
- ZX Spectrum Basic