Show ASCII table: Difference between revisions

m
syntax highlighting fixup automation
(add BQN)
m (syntax highlighting fixup automation)
Line 11:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">L(i) 16
L(j) (32 + i .. 127).step(16)
String k
Line 21:
k = Char(code' j)
print(‘#3 : #<3’.format(j, k), end' ‘’)
print()</langsyntaxhighlight>
 
{{out}}
Line 44:
 
=={{header|6502 Assembly}}==
<langsyntaxhighlight lang="asm">==========================================================================
; task : show ascii table
; language: 6502 Assembly
Line 163:
column .byte 0
ascii .byte 0
</syntaxhighlight>
</lang>
 
=={{header|8080 Assembly}}==
 
<langsyntaxhighlight lang="8080asm"> org 100h
mvi a,32 ; Start with space
mvi d,16 ; 16 lines
Line 234:
spc: db 'Spc ',0 ; Space
del: db 'Del ',0 ; Del
chr: db '* ',0 ; Placeholder for character</langsyntaxhighlight>
 
{{out}}
Line 258:
=={{header|8086 Assembly}}==
 
<langsyntaxhighlight lang="asm"> cpu 8086
bits 16
putch: equ 2h
Line 315:
spc: db 'Spc ',0 ; Space
del: db 'Del ',0 ; Del
chr: db '* ',0 ; Placeholder for character</langsyntaxhighlight>
 
{{out}}
Line 338:
=={{header|Action!}}==
Atari 8-bit computers use [https://en.wikipedia.org/wiki/ATASCII ATASCII] character set which is a variation of ASCII.
<langsyntaxhighlight Actionlang="action!">PROC Main()
BYTE
count=[96],rows=[16],
Line 372:
PutE()
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Show_ASCII_table.png Screenshot from Atari 8-bit computer]
Line 395:
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
 
Line 417:
New_Line;
end loop;
end Ascii_Table;</langsyntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 437:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN
# generate an ascii table for characters 32 - 127 #
INT char count := 1;
Line 452:
( char count PLUSAB 1 ) MODAB 6
OD
END</langsyntaxhighlight>
{{out}}
<pre> 32: SPC 33: ! 34: " 35: # 36: $ 37: %
Line 472:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% generate an ascii table for chars 32 - 127 %
integer cPos;
Line 484:
else writeon( code( i ), " " )
end for_i
end.</langsyntaxhighlight>
{{out}}
<pre> 32: Spc 33: ! 34: " 35: # 36: $ 37: %
Line 505:
=={{header|APL}}==
 
<langsyntaxhighlight APLlang="apl">{(¯3↑⍕⍵),': ',∊('Spc' 'Del'(⎕UCS ⍵))[32 127⍳⍵]}¨⍉6 16⍴31+⍳96</langsyntaxhighlight>
 
{{out}}
Line 527:
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">-- asciiTable :: () -> String
on asciiTable()
script row
Line 782:
set my text item delimiters to dlm
str
end unlines</langsyntaxhighlight>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 802:
 
=={{header|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.<langsyntaxhighlight lang="basic"> 0 GOTO 10: ONERR AI READ LY RND
10 LET X = 256 * PEEK (104)
11 LET X = X + PEEK (103) + 7
Line 821:
70 LET N$ = RIGHT$ (N$,4)
80 PRINT N$":" CHR$ (A + R);
90 NEXT C,R: PRINT</langsyntaxhighlight>
The 6502 routine is embedded at line 0 and is used to display the string "!TFOSORCIM" backwards.
<langsyntaxhighlight lang="asm"> LDA $41 ; ONERR A
EOR #$87 ; I READ
JMP $DB59 ; LY RND</langsyntaxhighlight>
=={{header|ARM Assembly}}==
Thanks to Keith of [https://www.chibiakumas.com ChibiAkumas] for creating the GBA bitmap font and I/O routines.
 
<langsyntaxhighlight ARMlang="arm Assemblyassembly">.equ CursorX,0x02000000
.equ CursorY,0x02000001
ProgramStart:
Line 1,117:
.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</langsyntaxhighlight>
 
{{out}}
Line 1,124:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">loop 32..127 'num [
k: ø
case [num]
Line 1,133:
prints pad ~"|num|: |k|" 10
if 1 = num%6 -> print ""
]</langsyntaxhighlight>
 
{{out}}
Line 1,155:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotKeylang="autohotkey">AutoTrim,Off ;Allows for whitespace at end of variable to separate converted characters
 
MessageText := ;The text to display in the final message box.
Line 1,184:
}
MsgBox, % MessageText ;Displays a message box with the ASCII conversion table, from the MessageText variable
return</langsyntaxhighlight>
{{out}}
<pre>
Line 1,207:
{{works with|GAWK}}
{{works with|MAWK}}
<langsyntaxhighlight AWKlang="awk"># syntax: GAWK -f SHOW_ASCII_TABLE.AWK
# syntax: MAWK -f SHOW_ASCII_TABLE.AWK
BEGIN {
Line 1,219:
print ""
}
}</langsyntaxhighlight>
{{out}}
<pre> 32: SPC 48: 0 64: @ 80: P 96: ` 112: p
Line 1,239:
 
=={{header|BASIC}}==
<langsyntaxhighlight lang="basic">10 DEFINT I,J: DEFSTR S: DIM S(2)
20 S(0)="* "
30 S(1)="Spc"
Line 1,249:
90 NEXT J
100 PRINT
110 NEXT I</langsyntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 1,269:
 
=={{header|BaCon}}==
<langsyntaxhighlight lang="bacon">FOR j = 0 TO 15
FOR i = 32+j TO 127 STEP 16
PRINT i FORMAT " %3d - ";
Line 1,282:
NEXT
PRINT
NEXT</langsyntaxhighlight>
 
{{out}}
Line 1,303:
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let str(n) =
Line 1,315:
writef(str(j), j, j)
wrch('*N')
$)</langsyntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 1,336:
=={{header|BQN}}==
The final result is a 2D array of characters which is output line by line with <code>•Out</code>.
<langsyntaxhighlight lang="bqn">chs←⟨"SPC"⟩∾(@+33+↕94)∾⟨"DEL"⟩
J←{𝕨∾' '∾𝕩}´
_pad←{(𝕗×·⌈´≠¨)⊸(↑¨)}
•Out˘J˘J¨⍉6‿16⥊<˘⍉(∾⟜':'¨¯1 _pad •Fmt¨32+↕96)≍1 _pad chs</langsyntaxhighlight>
<syntaxhighlight lang="text"> 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
Line 1,355:
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</langsyntaxhighlight>
=={{header|C}}==
{{trans|Go}}
<langsyntaxhighlight lang="c">#include <stdio.h>
 
int main() {
Line 1,375:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 1,395:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <string>
#include <iomanip>
#include <iostream>
Line 1,429:
std::cout << std::endl;
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,451:
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using static System.Console;
using static System.Linq.Enumerable;
 
Line 1,464:
string Text(int index) => index == 32 ? "Sp" : index == 127 ? "Del" : (char)index + "";
}
}</langsyntaxhighlight>
{{out}}
<pre> 32 : Sp 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 1,484:
 
=={{header|Caché ObjectScript}}==
<langsyntaxhighlight Cachélang="caché ObjectScriptobjectscript">SHOWASCII
; this is 96 characters, so do 6 columns of 16
for i = 32:1:127 {
Line 1,501:
}
 
quit</langsyntaxhighlight>
 
{{out}}
Line 1,528:
 
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.
<syntaxhighlight lang="clojure">
<lang Clojure>
(defn cell [code]
(let [text (get {32 "Spc", 127 "Del"} code (char code))]
Line 1,547:
(defn pr-ascii-table [n-cols st-code end-code]
(println (ascii-table n-cols st-code end-code)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,593:
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.
 
<syntaxhighlight lang="clojure">
<lang Clojure>
(defn cell [code]
(if (nil? code)
Line 1,616:
(defn pr-ascii-table [n-cols st-code end-code]
(println (ascii-table n-cols st-code end-code)))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,656:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">ascii = proc (n: int) returns (string)
if n=32 then return("Spc")
elseif n=127 then return("Del")
Line 1,673:
stream$putl(po, "")
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 1,695:
{{works with|OpenCOBOL|3.1.2}}
Uses free form syntax.
<syntaxhighlight lang="cobol">
<lang COBOL>
IDENTIFICATION DIVISION.
PROGRAM-ID. CHARSET.
Line 1,718:
END-PERFORM.
END PROGRAM CHARSET.
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,726:
 
=={{header|Commodore BASIC}}==
<langsyntaxhighlight lang="qbasic">100 PRINT CHR$(147);:REM CLEAR SCREEN
110 PRINT CHR$(14);:REM CHARACTER SET 2
120 PRINT "COMMODORE 64 - BASIC V2"
Line 1,738:
200 PRINT
210 NEXT R
</syntaxhighlight>
</lang>
{{out}}
[[File:c64asciitable.jpg]]
Line 1,745:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(setq startVal 32)
(setq endVal 127)
(setq cols 6)
Line 1,762:
(if (> lower upper) '() (cons lower (get-range (+ 1 lower) upper))))
 
(mapcar #'print-val (get-range startVal endVal))</langsyntaxhighlight>
{{out}}
<pre> 32: SPC 33: ! 34: " 35: # 36: $ 37: %
Line 1,782:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
# Print number with preceding space if <100 and trailing colon
Line 1,814:
end if;
end loop;
print_nl();</langsyntaxhighlight>
 
{{out}}
Line 1,837:
=={{header|D}}==
{{trans|C}}
<langsyntaxhighlight lang="d">import std.stdio;
 
void main() {
Line 1,856:
writeln;
}
}</langsyntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 1,879:
{{Works with|GNU dc|1.3.95}}
 
<langsyntaxhighlight lang="dc">[ [1q]S.[>.0]xs.L. ] sl ## l: islt
## for initcode condcode incrcode body
Line 1,910:
] lfx
[]pP
] lfx</langsyntaxhighlight>
{{out}}
<pre>
Line 1,934:
{{Trans|Go}}
 
<syntaxhighlight lang="delphi">
<lang Delphi>
program Show_Ascii_table;
 
Line 1,965:
end.
 
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,994:
 
{{Works with|Office 365 betas 2021}}
<langsyntaxhighlight lang="lisp">asciiTable
=LAMBDA(i,
justifyRight(3)(" ")(i) & ": " & (
Line 2,011:
)(
SEQUENCE(16, 6, 32, 1)
)</langsyntaxhighlight>
 
and also assuming the following generic binding in the Name Manager for the WorkBook:
 
<langsyntaxhighlight lang="lisp">justifyRight
=LAMBDA(n,
LAMBDA(c,
Line 2,033:
)
)
)</langsyntaxhighlight>
 
{{Out}}
Line 2,211:
Or, separating code and character into adjacent Excel cells:
 
<langsyntaxhighlight lang="lisp">asciiTable2
=LAMBDA(i,
IF(0 <> MOD(i, 1),
Line 2,229:
)(
SEQUENCE(16, 12, 32, 0.5)
)</langsyntaxhighlight>
 
{{Out}}
Line 2,513:
===Idiomatic version===
{{Works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: combinators formatting io kernel math math.ranges
pair-rocket sequences ;
IN: rosetta-code.ascii-table
Line 2,527:
: print-ascii-table ( -- ) 16 <iota> [ print-row ] each ;
 
MAIN: print-ascii-table</langsyntaxhighlight>
===Go translation===
{{Trans|Go}}
{{Works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: combinators formatting io kernel math math.ranges
pair-rocket sequences ;
IN: rosetta-code.ascii-table
Line 2,549:
;
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 2,570:
=={{header|Forth}}==
Idiomatic Forth version is factored differently than conventional languages, allowing each factor to be tested independently at the console, bottom up.
<langsyntaxhighlight lang="forth">DECIMAL
: ###: ( c -- ) 3 .R ." : " ;
 
Line 2,586:
 
: ASCII.TABLE ( -- )
16 0 DO 113 I + 32 I + .ROW LOOP ;</langsyntaxhighlight>
 
Test Output at the console
<langsyntaxhighlight lang="forth">ASCII.TABLE
32: spc 48: 0 64: @ 80: P 96: ` 112: p
33: ! 49: 1 65: A 81: Q 97: a 113: q
Line 2,606:
46: . 62: > 78: N 94: ^ 110: n 126: ~
47: / 63: ? 79: O 95: _ 111: o 127: del ok
</syntaxhighlight>
</lang>
 
 
Line 2,614:
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.
<langsyntaxhighlight Fortranlang="fortran"> PROGRAM ASCTBL ! show the ASCII characters from 32-127
IMPLICIT NONE
INTEGER I, J
Line 2,638:
 
END
</syntaxhighlight>
</lang>
output:
<pre> 32:Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 2,661:
=={{header|FreeBASIC}}==
 
<langsyntaxhighlight lang="freebasic">function getasc( n as unsigned byte ) as string
if n=32 then return "Spc"
if n=127 then return "Del"
Line 2,682:
print disp
next r
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,706:
=={{header|Free Pascal}}==
 
<langsyntaxhighlight lang="pascal">// The FPC (FreePascal compiler) discards the program header
// (except in ISO-compliant “compiler modes”).
program showAsciiTable(output);
Line 2,767:
end;
end;
end.</langsyntaxhighlight>
 
{{out}}
Line 2,789:
 
=={{header|Frink}}==
<langsyntaxhighlight lang="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"]]</langsyntaxhighlight>
{{out}}
<pre>
Line 2,826:
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
Line 2,858:
 
HandleEvents
</syntaxhighlight>
</lang>
{{output}}
<pre>
Line 2,881:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 2,899:
fmt.Println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,922:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">class ShowAsciiTable {
static void main(String[] args) {
for (int i = 32; i <= 127; i++) {
Line 2,936:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> 32: Spc 33: ! 34: " 35: # 36: $ 37: %
Line 2,956:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Char (chr)
import Data.List (transpose)
import Data.List.Split (chunksOf)
Line 2,988:
--------------------------- TEST -------------------------
main :: IO ()
main = putStrLn asciiTable</langsyntaxhighlight>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 3,008:
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 TEXT 80
110 FOR R=0 TO 15
120 FOR C=32+R TO 112+R STEP 16
Line 3,014:
140 NEXT
150 PRINT
160 NEXT</langsyntaxhighlight>
 
=={{header|J}}==
Line 3,079:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">
public class ShowAsciiTable {
 
Line 3,098:
 
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,120:
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">(() => {
 
"use strict";
Line 3,225:
// MAIN ---
return asciiTable();
})();</langsyntaxhighlight>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 3,245:
 
=={{header|Jsish}}==
<langsyntaxhighlight lang="javascript">#!/usr/bin/env jsish
 
/* Show ASCII table, -showAll true to include control codes */
Line 3,311:
015 SI 031 US 047 / 063 ? 079 O 095 _ 111 o 127 DEL
=!EXPECTEND!=
*/</langsyntaxhighlight>
{{out}}
<pre>prompt$ jsish -u showASCIITable.jsi
Line 3,340:
 
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.
<syntaxhighlight lang="jq">
<lang jq>
# Pretty printing
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
Line 3,368:
end
| lpad(4) ;
</syntaxhighlight>
</lang>
===Base Task===
<langsyntaxhighlight lang="jq"># produce a flat array
def prepare($m;$n):
[range($m; $n) | "\(lpad(7)): \(humanize)" ];
Line 3,379:
# Column-wise with 16 rows would be produced by:
# prepare(32;128) | ttable(16)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,401:
 
===Column-wise table of 128..255===
<syntaxhighlight lang="jq">
<lang jq>
# Column-wise representation with 16 rows
(prepare(128;256) | ttable(16))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,427:
=={{header|Julia}}==
===Base Task===
<langsyntaxhighlight lang="julia">for i in 32:127
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" :
i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|"
print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c")
(i&7)==7 ? println() : print(" ")
end</langsyntaxhighlight>{{out}}
<pre>
32 20 | | 33 21 |!| 34 22 |"| 35 23 |#| 36 24 |$| 37 25 |%| 38 26 |&| 39 27 |'|
Line 3,451:
{{works with|Julia|1.0}}
 
<langsyntaxhighlight lang="julia">for i in 0:255
c= i== 0 ? "NUL" : i== 7 ? "BEL" : i== 8 ? "BKS" : i== 9 ? "TAB" :
i==10 ? "LF " : i==13 ? "CR " : i==27 ? "ESC" : i==155 ? "CSI" : "|$(Char(i))|"
print("$(lpad(i,3)) $(string(i,base=16,pad=2)) $c")
(i&7)==7 ? println() : print(" ")
end</langsyntaxhighlight>
{{out}}
<pre> 0 00 NUL 1 01 |☺| 2 02 |☻| 3 03 |♥| 4 04 |♦| 5 05 |♣| 6 06 |♠| 7 07 BEL
Line 3,494:
This version draws a more fancy table, positioning the items on the console monitor with ANSI control sequences:
 
<langsyntaxhighlight lang="julia">print("\e[2J") # clear screen
print("""
0 1 2 3 4 5 6 7 8 9 A B C D E F
Line 3,518:
6<i<11 || i==155 || i==173 || print("\e[$r;$(c)H$(Char(i))")
end
print("\e[54;1H")</langsyntaxhighlight>
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9 A B C D E F
Line 3,573:
 
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.
<langsyntaxhighlight lang="julia">#= CONSOLE TABLES =============================================================
rn: nrows, rh: height of rows
cn: ncols, cw: width of columns
Line 3,620:
end
println("\n$t\n")
end</langsyntaxhighlight>
Using these is simple, only provide the data, and prt it.
<langsyntaxhighlight lang="julia">Tbl = Table(16,2,16,3, 2,3) # construct table
Tbl.CH[1,:] = string.(0:15,base=16) # Column headers
Tbl.RH[:,2] = string.(0:15,base=16) # Row headers
Line 3,628:
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</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Go}}
<langsyntaxhighlight lang="scala">// Version 1.2.60
 
fun main(args: Array<String>) {
Line 3,646:
println()
}
}</langsyntaxhighlight>
 
{{output}}
Line 3,669:
{{trans|Go}}
{{works with|langur|0.6.8}}
<langsyntaxhighlight lang="langur">for .i of 16 {
for .j = 31 + .i ; .j < 128 ; .j += 16 {
val .L = given(.j; 32: "spc"; 127: "del"; cp2s .j)
Line 3,675:
}
writeln()
}</langsyntaxhighlight>
 
{{out}}
Line 3,697:
=={{header|Locomotive Basic}}==
 
<langsyntaxhighlight lang="locobasic">10 mode 1:defint a-z
20 for x=1 to 6
30 for y=1 to 16
Line 3,705:
70 print " ";chr$(n);
80 next
90 next</langsyntaxhighlight>
 
{{out}}
Line 3,727:
=={{header|Lua}}==
{{trans|Go}}
<langsyntaxhighlight lang="lua">
-- map of character values to desired representation
local chars = setmetatable({[32] = "Spc", [127] = "Del"}, {__index = function(_, k) return string.char(k) end})
Line 3,743:
end
io.write"\n"
end</langsyntaxhighlight>
 
{{out}}
Line 3,764:
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Function ProduceAscii$ {
Document Ascii$="\"
Line 3,788:
}
Clipboard ProduceAscii$()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,801:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">StringRiffle[StringJoin@@@Transpose[Partition[ToString[#]<>": "<>Switch[#,32,"Spc ",127,"Del ",_,FromCharacterCode[#]<>" "]&/@Range[32,127],16]],"\n"]</langsyntaxhighlight>
{{out}}
<pre>32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 3,822:
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">// Prints ASCII table
// Note changing the values of startChar and endChar will print
// a flexible table in that range
Line 3,855:
end if
end for
if line then print line // final check for odd incomplete line output</langsyntaxhighlight>
{{out}}
<pre>
Line 3,878:
=={{header|Nanoquery}}==
{{trans|C}}
<langsyntaxhighlight Nanoquerylang="nanoquery">k = ""
for i in range(0, 15)
for j in range(32 + i, 127, 16)
Line 3,891:
end
println
end</langsyntaxhighlight>
 
{{out}}
Line 3,912:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strformat
for i in 0..15:
Line 3,921:
else: $chr(j)
write(stdout, fmt"{j:3d} : {k:<6s}")
write(stdout, "\n")</langsyntaxhighlight>
 
{{out}}
Line 3,945:
=={{header|Objeck}}==
{{trans|Java}}
<langsyntaxhighlight lang="objeck">class AsciiTable {
function : Main(args : String[]) ~ Nil {
for(i := 32; i <= 127 ; i += 1;) {
Line 3,961:
};
}
}</langsyntaxhighlight>
 
{{output}}
Line 3,984:
 
=={{header|OxygenBasic}}==
<syntaxhighlight lang="text">
uses console
int i,j
Line 4,002:
next
pause
</syntaxhighlight>
</lang>
 
=={{header|Perl}}==
Output in the same style as Raku.
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use charnames ':full';
binmode STDOUT, ':utf8';
 
Line 4,026:
}
}
print qq[|}\n];</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 4,038:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ascii</span><span style="color: #0000FF;">,</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">),</span><span style="color: #008000;">"\x7F"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"del"</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre> 32 (#20): 48 (#30): 0 64 (#40): @ 80 (#50): P 96 (#60): ` 112 (#70): p
Line 4,059:
=={{header|PHP}}==
 
<langsyntaxhighlight PHPlang="php"><?php
 
echo '+' . str_repeat('----------+', 6), PHP_EOL;
Line 4,074:
echo '|', PHP_EOL;
}
echo '+' . str_repeat('----------+', 6), PHP_EOL;</langsyntaxhighlight>
 
{{out}}
Line 4,097:
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="pli">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;
Line 4,126:
IF ( ( C - 31 ) MOD 6 ) = 0 THEN CALL PR$STRING( .( 0DH, 0AH, '$' ) );
END;
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 4,148:
 
=={{header|Prolog}}==
<langsyntaxhighlight Prologlang="prolog">ascii :-
forall(between(32, 47, N), row(N)).
 
Line 4,163:
ascii(32) :- write(' Spc '), !.
ascii(127) :- write(' Del '), !.
ascii(A) :- char_code(D,A), format(' ~w ', D).</langsyntaxhighlight>
{{out}}
<pre>
Line 4,189:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">If OpenConsole("Show_Ascii_table: rosettacode.org")
Define r.i, c.i
For r=0 To 15
Line 4,207:
Next
Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,229:
===Imperative===
{{trans|Go}}
<langsyntaxhighlight lang="python">
for i in range(16):
for j in range(32+i, 127+1, 16):
Line 4,240:
print("%3d : %-3s" % (j,k), end="")
print()
</syntaxhighlight>
</lang>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,261:
===HTML===
After Raku, but creating an HTML table:
<langsyntaxhighlight lang="python">from unicodedata import name
from html import escape
 
Line 4,276:
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>""")</langsyntaxhighlight>
 
{{out}}
Line 4,422:
 
Composed from generic abstractions:
<langsyntaxhighlight lang="python">'''Plain text ASCII code table'''
 
from functools import reduce
Line 4,529:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,549:
 
===List Comprehensions===
<langsyntaxhighlight lang="python">
# One-liner
# print('\n'.join([''.join(["%3d : %-3s" % (a, 'Spc' if a == 32 else 'Del' if a == 127 else chr(a)) for a in lst]) for lst in [[i+c*16 for c in range(6)] for i in range(32, 47+1)]])
Line 4,565:
 
# Joining columns into rows and printing rows one in a separate line
print('\n'.join([''.join(row) for row in rows_as_strings]))</langsyntaxhighlight>
{{Out}}
<pre> 32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 4,585:
 
=={{header|QB64}}==
<langsyntaxhighlight lang="qbasic">DIM s AS STRING
 
FOR i% = 32 TO 47
Line 4,600:
NEXT j%
PRINT
NEXT i%</langsyntaxhighlight>
{{out}}
<pre>
Line 4,622:
 
=={{header|Quackery}}==
<langsyntaxhighlight lang="quackery">
[ dup 32 = iff
[ drop say 'spc' ] done
Line 4,640:
 
echotable
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,662:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">chr <- function(n) {
rawToChar(as.raw(n))
}
Line 4,678:
idx <- idx + 6
cat("\n")
}</langsyntaxhighlight>
{{out}}
<pre> 32 : Spc 33 : ! 34 : " 35 : # 36 : $ 37 : %
Line 4,699:
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
 
(for ([i (in-range 16)])
Line 4,710:
[127 "DEL"]
[_ (integer->char n)]) #:min-width 5)))
(newline))</langsyntaxhighlight>
 
{{out}}
Line 4,735:
Alternately, and perhaps more usefully, output as a wiki-table rather than ASCII art. Hover mouse over the glyph to get the name.
 
<syntaxhighlight lang="raku" perl6line>sub glyph ($_) {
when * < 33 { (0x2400 + $_).chr } # display symbol names for invisible glyphs
when 127 { '␡' }
Line 4,750:
}
 
say '|}';</langsyntaxhighlight>
{{out}}
{|class="wikitable" style="text-align:center;background-color:hsl(39, 90%, 95%)"
Line 4,892:
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red ["ASCII table"]
 
repeat i 16 [
Line 4,904:
]
prin newline
]</langsyntaxhighlight>
{{out}}
<pre>
Line 4,940:
:::* &nbsp; the suppression of displaying particular glyphs by REXX that are preempted by the OS.
:::* &nbsp; adding homage to the adage of: &nbsp; ''anything worth doing is worth doing well''.
<langsyntaxhighlight lang="rexx">/*REXX program displays an ASCII table of characters (within a 16x16 indexed grid).*/
parse upper version !ver . /*some REXXes can't display '1b'x glyph*/
!pcRexx= 'REXX/PERSONAL'==!ver | "REXX/PC"==!ver /*is this PC/REXX or REXX/Personal? */
Line 4,981:
/*──────────────────────────────────────────────────────────────────────────────────────*/
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</langsyntaxhighlight>
{{out|output|text=&nbsp; showing a &nbsp; ''horizontal'' &nbsp; formatted grid (table):}}
 
Line 5,036:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Show Ascii table
 
Line 5,083:
}
exec()
}</langsyntaxhighlight>
Output:
 
Line 5,089:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">chars = (32..127).map do |ord|
k = case ord
when 32 then "␠"
Line 5,098:
end
chars.each_slice(chars.size/6).to_a.transpose.each{|s| puts s.join(" ")}</langsyntaxhighlight>
{{out}}
<pre>32 : ␠ 48 : 0 64 : @ 80 : P 96 : ` 112: p
Line 5,120:
=={{header|Rust}}==
{{trans|Go}}
<langsyntaxhighlight Rustlang="rust">fn main() {
for i in 0u8..16 {
for j in ((32+i)..128).step_by(16) {
Line 5,132:
println!();
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,155:
{{Out}}Best seen in running your browser either by [https://scalafiddle.io/sf/ouiyD9x/0 ScalaFiddle (your local ES aka JavaScript execution, non JVM)] or [https://scastie.scala-lang.org/OD7rBCSMQgKSyKKcGB24cg Scastie (remote JVM)].
{{works with|Scala|2.13}}
<langsyntaxhighlight Scalalang="scala">object AsciiTable extends App {
val (strtCharVal, lastCharVal, nColumns) = (' '.toByte, '\u007F'.toByte, 6)
require(nColumns % 2 == 0, "Number of columns must be even.")
Line 5,179:
.map(_.map(byte => f"$byte%3d : ${k(byte)}"))
.foreach(line => println(line.mkString(" ")))
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 5,202:
writeln;
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 5,227:
{{works with|HomeSpun}}
{{works with|OpenSpin}}
<langsyntaxhighlight lang="spin">con
_clkmode = xtal1+pll16x
_clkfreq = 80_000_000
Line 5,256:
 
waitcnt(_clkfreq + cnt)
ser.stop</langsyntaxhighlight>
{{out}}
<pre> 32: SPC 48: 0 64: @ 80: P 96: ` 112: p
Line 5,276:
 
=={{header|Standard ML}}==
<syntaxhighlight lang="text">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) ;</langsyntaxhighlight>
32: ' ' 33: '!' 34: '"' 35: '#' 36: '$' 37: '%' 38: '&' 39: '&apos;' 40: '(' 41: ')'
42: '*' 43: '+' 44: ',' 45: '-' 46: '.' 47: '/' 48: '0' 49: '1' 50: '2' 51: '3'
Line 5,294:
=={{header|Tcl}}==
{{trans|AWK}}
<syntaxhighlight lang="tcl">
<lang Tcl>
for {set i 0} {$i < 16} {incr i} {
for {set j $i} {$j < 128} {incr j 16} {
Line 5,306:
puts ""
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,328:
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang VB>
Public Sub ascii()
Dim s As String, i As Integer, j As Integer
Line 5,342:
Debug.Print vbCrLf
Next i
End Sub</langsyntaxhighlight>
{{out}}
<pre> 32: Spc 48: 0 64: @ 80: P 96: ` 112: p
Line 5,364:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Imports System.Console
Imports System.Linq.Enumerable
 
Line 5,377:
Loop While start + 16 * 5 < 128
End Sub
End Module</langsyntaxhighlight>
{{out}}
<pre>32 : Sp 48 : 0 64 : @ 80 : P 96 : ` 112 : p
Line 5,398:
=={{header|Vlang}}==
{{trans|go}}
<langsyntaxhighlight lang="vlang">fn main() {
for i in 0..16{
for j := 32 + i; j < 128; j += 16 {
Line 5,415:
println('')
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,439:
{{trans|Go}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Fmt
 
for (i in 0...16) {
Line 5,454:
}
System.print()
}</langsyntaxhighlight>
 
{{out}}
Line 5,477:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int Hi, Lo;
[SetHexDigits(2);
Text(0, " ");
Line 5,489:
CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 5,513:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">const width=9;
println(" ",[0..width].pump(String,"%4d".fmt));
[30..127].pump("".println,T(Void.Read,width,False), // don't fail on short lines
Line 5,522:
T("replace"," ","spc"),T("replace","\x7f","del"), "%-4s".fmt)
)
})</langsyntaxhighlight>
{{out}}
<pre> 0 1 2 3 4 5 6 7 8 9
Line 5,538:
=={{header|ZX Spectrum Basic}}==
Note in particular entries 94, 96 and 127.
<langsyntaxhighlight lang="zxbasic">10 FOR x=0 TO 9
20 PRINT AT 0,4+2*x;x
30 PRINT AT x+1,0;10*(3+x)
Line 5,546:
70 LET t=(x-d)/10
80 PRINT AT t-2,4+2*d;CHR$ x
90 NEXT x</langsyntaxhighlight>
 
{{out}}
10,327

edits