Character codes: Difference between revisions
m
Added Plain English
No edit summary |
m (Added Plain English) |
||
(13 intermediate revisions by 9 users not shown) | |||
Line 493:
babel
=={{header|BASIC}}==
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">charCode = 97
Line 527 ⟶ 528:
$: 36
€: 8364, 36</pre>
==={{header|Chipmunk Basic}}===
<syntaxhighlight lang="qbasic">10 print "a - > ";asc("a")
20 print "98 -> ";chr$(98)</syntaxhighlight>
==={{header|Commodore BASIC}}===
Line 536 ⟶ 541:
{{Out}}<pre>A
66</pre>
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
<syntaxhighlight lang="qbasic">10 PRINT "a - > "; ASC("a")
20 PRINT "98 -> "; CHR$(98)</syntaxhighlight>
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PRINT ORD("A")
110 PRINT CHR$(65)</syntaxhighlight>
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
<syntaxhighlight lang="qbasic">10 PRINT "a - > "; ASC("a")
20 PRINT "98 -> "; CHR$(98)</syntaxhighlight>
==={{header|QBasic}}===
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|FreeBASIC}}
{{works with|GW-BASIC}}
{{works with|MSX BASIC}}
{{works with|PC-BASIC}}
{{works with|Run BASIC}}
{{works with|Yabasic}}
<syntaxhighlight lang="qbasic">PRINT "a - > "; ASC("a")
PRINT "98 -> "; CHR$(98)</syntaxhighlight>
Line 555 ⟶ 577:
<pre>38
A</pre>
==={{header|SmallBASIC}}===
<syntaxhighlight lang="qbasic">
Print "a -> "; Asc("a")
Print "98 -> "; Chr(98)
</syntaxhighlight>
==={{header|True BASIC}}===
Line 560 ⟶ 588:
PRINT "98 -> "; chr$(98)
END</syntaxhighlight>
==={{header|XBasic}}===
{{works with|Windows XBasic}}
{{works with|Linux XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Character codes"
VERSION "0.0000"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
PRINT "a - >"; ASC("a")
PRINT "98 -> "; CHR$(98)
END FUNCTION
END PROGRAM</syntaxhighlight>
==={{header|Yabasic}}===
Line 906 ⟶ 948:
Limitations: There is no "put_character_32" feature for standard io (FILE class), so there appears to be no way to print Unicode characters.
=={{header|Elena}}==
ELENA
<syntaxhighlight lang="elena">import extensions;
Line 913 ⟶ 955:
var ch := $97;
console.printLine
console.printLine(ch.toInt())
}</syntaxhighlight>
Line 921 ⟶ 963:
97
</pre>
=={{header|Elixir}}==
A String in Elixir is a UTF-8 encoded binary.
Line 1,003 ⟶ 1,046:
fansh> 'a'.toInt
97</syntaxhighlight>
=={{header|Fennel}}==
<syntaxhighlight lang="fennel">
(string.byte :A) ; 65
(string.char 65) ; "A"
</syntaxhighlight>
=={{header|Forth}}==
As with C, characters are just integers on the stack which are treated as ASCII.
Line 1,342 ⟶ 1,392:
Langur has code point literals (enclosed in straight single quotes), which may use escape codes. They are integers.
The s2cp(), cp2s(), and
<syntaxhighlight lang="langur">val .a1 = 'a'
Line 1,354 ⟶ 1,404:
writeln .a3 == .a4
writeln "numbers: ", join ", ", [.a1, .a2, .a3, .a4, .a5]
writeln "letters: ", join ", ", map cp2s, [
{{out}}
Line 1,363 ⟶ 1,413:
letters: a, a, a, a, aaaa
</pre>
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">'a'->integer
Line 1,535 ⟶ 1,586:
The character for '65' is: A.
Press any key to continue...</syntaxhighlight>
=={{header|MiniScript}}==
{{trans|Wren}}
MiniScript does not have a ''character'' type as such but one can use single character strings instead. Strings can contain any Unicode code point.
<syntaxhighlight lang="miniscript">cps = []
for c in ["a", "π", "字", "🐘"]
cp = c.code
cps.push cp
print c + " = " + cp
end for
print
for i in cps
print i + " = " + char(i)
end for</syntaxhighlight>
{{out}}
<pre>a = 97
π = 960
字 = 23383
🐘 = 128024
97 = a
960 = π
23383 = 字
128024 = 🐘
</pre>
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE asc;
Line 1,557 ⟶ 1,634:
<syntaxhighlight lang="modula-2">jan@Beryllium:~/modula/rosetta$ ./asc
a 97 1</syntaxhighlight>
=={{header|Modula-3}}==
The built in functions <code>ORD</code> and <code>VAL</code> work on characters, among other things.
Line 1,759 ⟶ 1,837:
<syntaxhighlight lang="pascal">writeln(ord('a'));
writeln(chr(97));</syntaxhighlight>
=={{header|Plain English}}==
<syntaxhighlight>
\ Obs: The little-a byte is a byte equal to 97.
Write the little-a byte's whereabouts on the console.
Put 97 into a number.
Write the number's target on the console.
</syntaxhighlight>
=={{header|Perl}}==
===Narrow===
Line 2,643 ⟶ 2,728:
test = (chr97,asc`a)</syntaxhighlight>
{{Out}}<pre>(`a,97)</pre>
=={{header|Uxntal}}==
<syntaxhighlight lang="Uxntal">
( uxnasm char-codes.tal char-codes.rom && uxncli char-codes.rom )
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|0100
[ LIT "a ] print-hex
newline
#61 .Console/write DEO
newline
( exit )
#80 .System/state DEO
BRK
@print-hex
DUP #04 SFT print-digit #0f AND print-digit
JMP2r
@print-digit
DUP #09 GTH #27 MUL ADD #30 ADD .Console/write DEO
JMP2r
@newline
#0a .Console/write DEO
JMP2r</syntaxhighlight>
Output:
<pre>61
a</pre>
=={{header|VBA}}==
<syntaxhighlight lang="vba">Debug.Print Chr(97) 'Prints a
Line 2,687 ⟶ 2,806:
=={{header|Wren}}==
Wren does not have a ''character'' type as such but one can use single character strings instead. Strings can contain any Unicode code point.
<syntaxhighlight lang="
for (c in ["a", "π", "字", "🐘"]) {
var cp = c.codePoints[0]
Line 2,711 ⟶ 2,830:
128024 = 🐘
</pre>
=={{header|XLISP}}==
In a REPL:
Line 2,753 ⟶ 2,873:
=={{header|Zig}}==
<syntaxhighlight lang="zig">const std = @import("std");
const unicode = std.unicode;
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try characterAsciiCodes(stdout);
try characterUnicodeCodes(stdout);
}
fn characterAsciiCodes(writer: anytype) !void {
try writer.writeAll("Sample ASCII characters and codes:\n");
// Zig's string is just an array of bytes (u8).
const message: []const u8 = "ABCabc";
for (message) |val| {
}
try writer.writeByte('\n');
}
fn characterUnicodeCodes(writer: anytype) !void {
try writer.writeAll("Sample Unicode characters and codes:\n");
const message: []const u8 = "あいうえお";
const utf8_view = unicode.Utf8View.initUnchecked(message);
Line 2,778 ⟶ 2,904:
while (iter.nextCodepoint()) |val| {
var array: [4]u8 = undefined;
}
try writer.writeByte('\n');
}</syntaxhighlight>
{{out}}
<pre>
'A' code: 65 [hexa: 0x41]
'B' code: 66 [hexa: 0x42]
Line 2,792 ⟶ 2,919:
'b' code: 98 [hexa: 0x62]
'c' code: 99 [hexa: 0x63]
Sample Unicode characters and codes:
'あ' code: 12354 [hexa: U+3042]
'い' code: 12356 [hexa: U+3044]
'う' code: 12358 [hexa: U+3046]
'え' code: 12360 [hexa: U+3048]
'お' code: 12362 [hexa: U+304a]</pre>
=={{header|zkl}}==
The character set is 8 bit ASCII (but doesn't care if you use UTF-8 or unicode characters).
|