Jump to content

Character codes: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→‎{{header|Perl 6}}: Just playing around because I can)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 63:
a
</pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
Line 541 ⟶ 542:
printf("%d\n", 'a'); /* prints "97" */
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;
}</lang>
Line 571 ⟶ 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>
 
Line 602 ⟶ 603:
)
000000043</pre>
 
=={{header|CoffeeScript}}==
CoffeeScript transcompiles to JavaScript, so it uses the JS standard library.
Line 746 ⟶ 747:
(message "%c" 97)
</lang>
 
 
=={{header|Erlang}}==
Line 798:
<lang fortran>WRITE(*,*) ACHAR(97), IACHAR("a")
WRITE(*,*) CHAR(97), ICHAR("a")</lang>
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
 
=={{header|FreeBASIC}}==
Line 815 ⟶ 818:
98 -> b
</pre>
 
=={{header|Free Pascal}}==
''See [[#Pascal|Pascal]]''
 
=={{header|Frink}}==
Line 942:
=={{header|HicEst}}==
<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}}==
Line 959 ⟶ 963:
{{Out}}<pre>97 ==> a
a ==> 97</pre>
 
=={{header|HolyC}}==
<lang holyc>Print("%d\n", 'a'); /* prints "97" */
Print("%c\n", 97); /* prints "a" */</lang>
 
=={{header|Io}}==
Line 1,307:
The character for '65' is: A.
Press any key to continue...</lang>
 
 
 
=={{header|Modula-2}}==
Line 1,337 ⟶ 1,335:
<lang modula3>ORD('a') (* Returns 97 *)
VAL(97, CHAR); (* Returns 'a' *)</lang>
 
 
=={{header|MUMPS}}==
<lang MUMPS>WRITE $ASCII("M")
WRITE $CHAR(77)</lang>
 
 
=={{header|Nanoquery}}==
Line 1,505 ⟶ 1,501:
{{Out}}<pre>
97
a</pre>
 
=={{header|Objeck}}==
<lang objeck>'a'->As(Int)->PrintLine();
Line 1,649 ⟶ 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
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}}==
Line 1,884 ⟶ 1,769:
(char 97)
(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}}==
Line 2,151 ⟶ 2,149:
<lang seed7>writeln(ord('a'));
writeln(chr(97));</lang>
 
 
=={{header|SenseTalk}}==
<lang sensetalk>put CharToNum("a")
put NumToChar(97)</lang>
 
=={{header|Sidef}}==
<lang ruby>say 'a'.ord; # => 97
say 97.chr; # => 'a'</lang>
 
=={{header|SequenceL}}==
Line 2,168 ⟶ 2,161:
cmd:>intToAscii(97)
'a'</lang>
 
=={{header|Sidef}}==
<lang ruby>say 'a'.ord; # => 97
say 97.chr; # => 'a'</lang>
 
=={{header|Slate}}==
Line 2,371 ⟶ 2,368:
echo nr2char(97)
"Prints a</lang>
 
 
=={{header|Visual Basic .NET}}==
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.