Character codes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Just playing around because I can) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 63: | Line 63: | ||
a |
a |
||
</pre> |
</pre> |
||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
Line 541: | Line 542: | ||
printf("%d\n", 'a'); /* prints "97" */ |
printf("%d\n", 'a'); /* prints "97" */ |
||
printf("%c\n", 97); /* prints "a"; we don't have to cast because printf is type agnostic */ |
printf("%c\n", 97); /* prints "a"; we don't have to cast because printf is type agnostic */ |
||
return 0; |
|||
}</lang> |
|||
=={{header|C++}}== |
|||
<tt>char</tt> is already an integer type in C++, and it gets automatically promoted to <tt>int</tt>. So you can use a character where you would otherwise use an integer. Conversely, you can use an integer where you would normally use a character, except you may need to cast it, as <tt>char</tt> is smaller. |
|||
In this case, the output operator <tt><<</tt> is overloaded to handle integer (outputs the decimal representation) and character (outputs just the character) types differently, so we need to cast it in both cases. |
|||
<lang cpp>#include <iostream> |
|||
int main() { |
|||
std::cout << (int)'a' << std::endl; // prints "97" |
|||
std::cout << (char)97 << std::endl; // prints "a" |
|||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
Line 571: | Line 560: | ||
} |
} |
||
} |
} |
||
}</lang> |
|||
=={{header|C++}}== |
|||
<tt>char</tt> is already an integer type in C++, and it gets automatically promoted to <tt>int</tt>. So you can use a character where you would otherwise use an integer. Conversely, you can use an integer where you would normally use a character, except you may need to cast it, as <tt>char</tt> is smaller. |
|||
In this case, the output operator <tt><<</tt> is overloaded to handle integer (outputs the decimal representation) and character (outputs just the character) types differently, so we need to cast it in both cases. |
|||
<lang cpp>#include <iostream> |
|||
int main() { |
|||
std::cout << (int)'a' << std::endl; // prints "97" |
|||
std::cout << (char)97 << std::endl; // prints "a" |
|||
return 0; |
|||
}</lang> |
}</lang> |
||
Line 602: | Line 603: | ||
) |
) |
||
000000043</pre> |
000000043</pre> |
||
=={{header|CoffeeScript}}== |
=={{header|CoffeeScript}}== |
||
CoffeeScript transcompiles to JavaScript, so it uses the JS standard library. |
CoffeeScript transcompiles to JavaScript, so it uses the JS standard library. |
||
Line 746: | Line 747: | ||
(message "%c" 97) |
(message "%c" 97) |
||
</lang> |
</lang> |
||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
Line 798: | Line 798: | ||
<lang fortran>WRITE(*,*) ACHAR(97), IACHAR("a") |
<lang fortran>WRITE(*,*) ACHAR(97), IACHAR("a") |
||
WRITE(*,*) CHAR(97), ICHAR("a")</lang> |
WRITE(*,*) CHAR(97), ICHAR("a")</lang> |
||
=={{header|Free Pascal}}== |
|||
''See [[#Pascal|Pascal]]'' |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
Line 815: | Line 818: | ||
98 -> b |
98 -> b |
||
</pre> |
</pre> |
||
=={{header|Free Pascal}}== |
|||
''See [[#Pascal|Pascal]]'' |
|||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
Line 942: | Line 942: | ||
=={{header|HicEst}}== |
=={{header|HicEst}}== |
||
<lang hicest>WRITE(Messagebox) ICHAR('a'), CHAR(97)</lang> |
<lang hicest>WRITE(Messagebox) ICHAR('a'), CHAR(97)</lang> |
||
=={{header|HolyC}}== |
|||
<lang holyc>Print("%d\n", 'a'); /* prints "97" */ |
|||
Print("%c\n", 97); /* prints "a" */</lang> |
|||
=={{header|i}}== |
=={{header|i}}== |
||
Line 959: | Line 963: | ||
{{Out}}<pre>97 ==> a |
{{Out}}<pre>97 ==> a |
||
a ==> 97</pre> |
a ==> 97</pre> |
||
=={{header|HolyC}}== |
|||
<lang holyc>Print("%d\n", 'a'); /* prints "97" */ |
|||
Print("%c\n", 97); /* prints "a" */</lang> |
|||
=={{header|Io}}== |
=={{header|Io}}== |
||
Line 1,307: | Line 1,307: | ||
The character for '65' is: A. |
The character for '65' is: A. |
||
Press any key to continue...</lang> |
Press any key to continue...</lang> |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
Line 1,337: | Line 1,335: | ||
<lang modula3>ORD('a') (* Returns 97 *) |
<lang modula3>ORD('a') (* Returns 97 *) |
||
VAL(97, CHAR); (* Returns 'a' *)</lang> |
VAL(97, CHAR); (* Returns 'a' *)</lang> |
||
=={{header|MUMPS}}== |
=={{header|MUMPS}}== |
||
<lang MUMPS>WRITE $ASCII("M") |
<lang MUMPS>WRITE $ASCII("M") |
||
WRITE $CHAR(77)</lang> |
WRITE $CHAR(77)</lang> |
||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
Line 1,505: | Line 1,501: | ||
{{Out}}<pre> |
{{Out}}<pre> |
||
97 |
97 |
||
a</pre> |
a</pre> |
||
=={{header|Objeck}}== |
=={{header|Objeck}}== |
||
<lang objeck>'a'->As(Int)->PrintLine(); |
<lang objeck>'a'->As(Int)->PrintLine(); |
||
Line 1,649: | Line 1,646: | ||
UTF-8: f0 9f 91 a8 e2 80 8d f0 9f 91 a9 e2 80 8d f0 9f 91 a7 e2 80 8d f0 9f 91 a6 |
UTF-8: f0 9f 91 a8 e2 80 8d f0 9f 91 a9 e2 80 8d f0 9f 91 a7 e2 80 8d f0 9f 91 a6 |
||
Round trip: 👨👩👧👦</pre> |
Round trip: 👨👩👧👦</pre> |
||
=={{header|Perl 6}}== |
|||
Both Perl 5 and Perl 6 have good Unicode support, though Perl 6 attempts to make working with Unicode effortless. Note that even multi-byte emoji and characters outside the BMP are considered single characters. Also note: all of these routines are built into the base compiler. No need to load external libraries. See [[wp:Unicode_character_property#General_Category|Wikipedia: Unicode character properties]] for explanation of Unicode property. |
|||
<lang perl6>for 'AΑА𪚥🇺🇸👨👩👧👦'.comb { |
|||
.put for |
|||
[ 'Character', |
|||
'Character name', |
|||
'Unicode property', |
|||
'Unicode script', |
|||
'Unicode block', |
|||
'Ordinal(s)', |
|||
'Hex ordinal(s)', |
|||
'UTF-8', |
|||
'UTF-16LE', |
|||
'UTF-16BE', |
|||
'Round trip by name', |
|||
'Round trip by ordinal' |
|||
]».fmt('%21s:') |
|||
Z |
|||
[ $_, |
|||
.uninames.join(', '), |
|||
.uniprops.join(', '), |
|||
.uniprops('Script').join(', '), |
|||
.uniprops('Block').join(', '), |
|||
.ords, |
|||
.ords.fmt('0x%X'), |
|||
.encode('utf8' )».fmt('%02X'), |
|||
.encode('utf16le')».fmt('%02X').join.comb(4), |
|||
.encode('utf16be')».fmt('%02X').join.comb(4), |
|||
.uninames».uniparse.join, |
|||
.ords.chrs |
|||
]; |
|||
say ''; |
|||
}</lang> |
|||
{{out}} |
|||
<pre> Character: A |
|||
Character name: LATIN CAPITAL LETTER A |
|||
Unicode property: Lu |
|||
Unicode script: Latin |
|||
Unicode block: Basic Latin |
|||
Ordinal(s): 65 |
|||
Hex ordinal(s): 0x41 |
|||
UTF-8: 41 |
|||
UTF-16LE: 4100 |
|||
UTF-16BE: 0041 |
|||
Round trip by name: A |
|||
Round trip by ordinal: A |
|||
Character: Α |
|||
Character name: GREEK CAPITAL LETTER ALPHA |
|||
Unicode property: Lu |
|||
Unicode script: Greek |
|||
Unicode block: Greek and Coptic |
|||
Ordinal(s): 913 |
|||
Hex ordinal(s): 0x391 |
|||
UTF-8: CE 91 |
|||
UTF-16LE: 9103 |
|||
UTF-16BE: 0391 |
|||
Round trip by name: Α |
|||
Round trip by ordinal: Α |
|||
Character: А |
|||
Character name: CYRILLIC CAPITAL LETTER A |
|||
Unicode property: Lu |
|||
Unicode script: Cyrillic |
|||
Unicode block: Cyrillic |
|||
Ordinal(s): 1040 |
|||
Hex ordinal(s): 0x410 |
|||
UTF-8: D0 90 |
|||
UTF-16LE: 1004 |
|||
UTF-16BE: 0410 |
|||
Round trip by name: А |
|||
Round trip by ordinal: А |
|||
Character: 𪚥 |
|||
Character name: CJK UNIFIED IDEOGRAPH-2A6A5 |
|||
Unicode property: Lo |
|||
Unicode script: Han |
|||
Unicode block: CJK Unified Ideographs Extension B |
|||
Ordinal(s): 173733 |
|||
Hex ordinal(s): 0x2A6A5 |
|||
UTF-8: F0 AA 9A A5 |
|||
UTF-16LE: 69D8 A5DE |
|||
UTF-16BE: D869 DEA5 |
|||
Round trip by name: 𪚥 |
|||
Round trip by ordinal: 𪚥 |
|||
Character: 🇺🇸 |
|||
Character name: REGIONAL INDICATOR SYMBOL LETTER U, REGIONAL INDICATOR SYMBOL LETTER S |
|||
Unicode property: So, So |
|||
Unicode script: Common, Common |
|||
Unicode block: Enclosed Alphanumeric Supplement, Enclosed Alphanumeric Supplement |
|||
Ordinal(s): 127482 127480 |
|||
Hex ordinal(s): 0x1F1FA 0x1F1F8 |
|||
UTF-8: F0 9F 87 BA F0 9F 87 B8 |
|||
UTF-16LE: 3CD8 FADD 3CD8 F8DD |
|||
UTF-16BE: D83C DDFA D83C DDF8 |
|||
Round trip by name: 🇺🇸 |
|||
Round trip by ordinal: 🇺🇸 |
|||
Character: 👨👩👧👦 |
|||
Character name: MAN, ZERO WIDTH JOINER, WOMAN, ZERO WIDTH JOINER, GIRL, ZERO WIDTH JOINER, BOY |
|||
Unicode property: So, Cf, So, Cf, So, Cf, So |
|||
Unicode script: Common, Inherited, Common, Inherited, Common, Inherited, Common |
|||
Unicode block: Miscellaneous Symbols and Pictographs, General Punctuation, Miscellaneous Symbols and Pictographs, General Punctuation, Miscellaneous Symbols and Pictographs, General Punctuation, Miscellaneous Symbols and Pictographs |
|||
Ordinal(s): 128104 8205 128105 8205 128103 8205 128102 |
|||
Hex ordinal(s): 0x1F468 0x200D 0x1F469 0x200D 0x1F467 0x200D 0x1F466 |
|||
UTF-8: F0 9F 91 A8 E2 80 8D F0 9F 91 A9 E2 80 8D F0 9F 91 A7 E2 80 8D F0 9F 91 A6 |
|||
UTF-16LE: 3DD8 68DC 0D20 3DD8 69DC 0D20 3DD8 67DC 0D20 3DD8 66DC |
|||
UTF-16BE: D83D DC68 200D D83D DC69 200D D83D DC67 200D D83D DC66 |
|||
Round trip by name: 👨👩👧👦 |
|||
Round trip by ordinal: 👨👩👧👦</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 1,884: | Line 1,769: | ||
(char 97) |
(char 97) |
||
(char 955)</lang> |
(char 955)</lang> |
||
=={{header|Raku}}== |
|||
(formerly Perl 6) |
|||
Both Perl 5 and Perl 6 have good Unicode support, though Perl 6 attempts to make working with Unicode effortless. Note that even multi-byte emoji and characters outside the BMP are considered single characters. Also note: all of these routines are built into the base compiler. No need to load external libraries. See [[wp:Unicode_character_property#General_Category|Wikipedia: Unicode character properties]] for explanation of Unicode property. |
|||
<lang perl6>for 'AΑА𪚥🇺🇸👨👩👧👦'.comb { |
|||
.put for |
|||
[ 'Character', |
|||
'Character name', |
|||
'Unicode property', |
|||
'Unicode script', |
|||
'Unicode block', |
|||
'Ordinal(s)', |
|||
'Hex ordinal(s)', |
|||
'UTF-8', |
|||
'UTF-16LE', |
|||
'UTF-16BE', |
|||
'Round trip by name', |
|||
'Round trip by ordinal' |
|||
]».fmt('%21s:') |
|||
Z |
|||
[ $_, |
|||
.uninames.join(', '), |
|||
.uniprops.join(', '), |
|||
.uniprops('Script').join(', '), |
|||
.uniprops('Block').join(', '), |
|||
.ords, |
|||
.ords.fmt('0x%X'), |
|||
.encode('utf8' )».fmt('%02X'), |
|||
.encode('utf16le')».fmt('%02X').join.comb(4), |
|||
.encode('utf16be')».fmt('%02X').join.comb(4), |
|||
.uninames».uniparse.join, |
|||
.ords.chrs |
|||
]; |
|||
say ''; |
|||
}</lang> |
|||
{{out}} |
|||
<pre> Character: A |
|||
Character name: LATIN CAPITAL LETTER A |
|||
Unicode property: Lu |
|||
Unicode script: Latin |
|||
Unicode block: Basic Latin |
|||
Ordinal(s): 65 |
|||
Hex ordinal(s): 0x41 |
|||
UTF-8: 41 |
|||
UTF-16LE: 4100 |
|||
UTF-16BE: 0041 |
|||
Round trip by name: A |
|||
Round trip by ordinal: A |
|||
Character: Α |
|||
Character name: GREEK CAPITAL LETTER ALPHA |
|||
Unicode property: Lu |
|||
Unicode script: Greek |
|||
Unicode block: Greek and Coptic |
|||
Ordinal(s): 913 |
|||
Hex ordinal(s): 0x391 |
|||
UTF-8: CE 91 |
|||
UTF-16LE: 9103 |
|||
UTF-16BE: 0391 |
|||
Round trip by name: Α |
|||
Round trip by ordinal: Α |
|||
Character: А |
|||
Character name: CYRILLIC CAPITAL LETTER A |
|||
Unicode property: Lu |
|||
Unicode script: Cyrillic |
|||
Unicode block: Cyrillic |
|||
Ordinal(s): 1040 |
|||
Hex ordinal(s): 0x410 |
|||
UTF-8: D0 90 |
|||
UTF-16LE: 1004 |
|||
UTF-16BE: 0410 |
|||
Round trip by name: А |
|||
Round trip by ordinal: А |
|||
Character: 𪚥 |
|||
Character name: CJK UNIFIED IDEOGRAPH-2A6A5 |
|||
Unicode property: Lo |
|||
Unicode script: Han |
|||
Unicode block: CJK Unified Ideographs Extension B |
|||
Ordinal(s): 173733 |
|||
Hex ordinal(s): 0x2A6A5 |
|||
UTF-8: F0 AA 9A A5 |
|||
UTF-16LE: 69D8 A5DE |
|||
UTF-16BE: D869 DEA5 |
|||
Round trip by name: 𪚥 |
|||
Round trip by ordinal: 𪚥 |
|||
Character: 🇺🇸 |
|||
Character name: REGIONAL INDICATOR SYMBOL LETTER U, REGIONAL INDICATOR SYMBOL LETTER S |
|||
Unicode property: So, So |
|||
Unicode script: Common, Common |
|||
Unicode block: Enclosed Alphanumeric Supplement, Enclosed Alphanumeric Supplement |
|||
Ordinal(s): 127482 127480 |
|||
Hex ordinal(s): 0x1F1FA 0x1F1F8 |
|||
UTF-8: F0 9F 87 BA F0 9F 87 B8 |
|||
UTF-16LE: 3CD8 FADD 3CD8 F8DD |
|||
UTF-16BE: D83C DDFA D83C DDF8 |
|||
Round trip by name: 🇺🇸 |
|||
Round trip by ordinal: 🇺🇸 |
|||
Character: 👨👩👧👦 |
|||
Character name: MAN, ZERO WIDTH JOINER, WOMAN, ZERO WIDTH JOINER, GIRL, ZERO WIDTH JOINER, BOY |
|||
Unicode property: So, Cf, So, Cf, So, Cf, So |
|||
Unicode script: Common, Inherited, Common, Inherited, Common, Inherited, Common |
|||
Unicode block: Miscellaneous Symbols and Pictographs, General Punctuation, Miscellaneous Symbols and Pictographs, General Punctuation, Miscellaneous Symbols and Pictographs, General Punctuation, Miscellaneous Symbols and Pictographs |
|||
Ordinal(s): 128104 8205 128105 8205 128103 8205 128102 |
|||
Hex ordinal(s): 0x1F468 0x200D 0x1F469 0x200D 0x1F467 0x200D 0x1F466 |
|||
UTF-8: F0 9F 91 A8 E2 80 8D F0 9F 91 A9 E2 80 8D F0 9F 91 A7 E2 80 8D F0 9F 91 A6 |
|||
UTF-16LE: 3DD8 68DC 0D20 3DD8 69DC 0D20 3DD8 67DC 0D20 3DD8 66DC |
|||
UTF-16BE: D83D DC68 200D D83D DC69 200D D83D DC67 200D D83D DC66 |
|||
Round trip by name: 👨👩👧👦 |
|||
Round trip by ordinal: 👨👩👧👦</pre> |
|||
=={{header|RapidQ}}== |
=={{header|RapidQ}}== |
||
Line 2,151: | Line 2,149: | ||
<lang seed7>writeln(ord('a')); |
<lang seed7>writeln(ord('a')); |
||
writeln(chr(97));</lang> |
writeln(chr(97));</lang> |
||
=={{header|SenseTalk}}== |
=={{header|SenseTalk}}== |
||
<lang sensetalk>put CharToNum("a") |
<lang sensetalk>put CharToNum("a") |
||
put NumToChar(97)</lang> |
put NumToChar(97)</lang> |
||
=={{header|Sidef}}== |
|||
<lang ruby>say 'a'.ord; # => 97 |
|||
say 97.chr; # => 'a'</lang> |
|||
=={{header|SequenceL}}== |
=={{header|SequenceL}}== |
||
Line 2,168: | Line 2,161: | ||
cmd:>intToAscii(97) |
cmd:>intToAscii(97) |
||
'a'</lang> |
'a'</lang> |
||
=={{header|Sidef}}== |
|||
<lang ruby>say 'a'.ord; # => 97 |
|||
say 97.chr; # => 'a'</lang> |
|||
=={{header|Slate}}== |
=={{header|Slate}}== |
||
Line 2,371: | Line 2,368: | ||
echo nr2char(97) |
echo nr2char(97) |
||
"Prints a</lang> |
"Prints a</lang> |
||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |