CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
1
Task/Character-codes/0DESCRIPTION
Normal file
1
Task/Character-codes/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
Given a character value in your language, print its code (could be ASCII code, Unicode code, or whatever your language uses). For example, the character 'a' (lowercase letter A) has a code of 97 in ASCII (as well as Unicode, as ASCII forms the beginning of Unicode). Conversely, given a code, print out the corresponding character.
|
||||
5
Task/Character-codes/1META.yaml
Normal file
5
Task/Character-codes/1META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Basic language learning
|
||||
- String manipulation
|
||||
note: Text processing
|
||||
7
Task/Character-codes/ABAP/character-codes.abap
Normal file
7
Task/Character-codes/ABAP/character-codes.abap
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
report zcharcode
|
||||
data: c value 'A', n type i.
|
||||
field-symbols <n> type x.
|
||||
|
||||
assign c to <n> casting.
|
||||
move <n> to n.
|
||||
write: c, '=', n left-justified.
|
||||
2
Task/Character-codes/ACL2/character-codes.acl2
Normal file
2
Task/Character-codes/ACL2/character-codes.acl2
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(cw "~x0" (char-code #\a))
|
||||
(cw "~x0" (code-char 97))
|
||||
4
Task/Character-codes/ALGOL-68/character-codes-1.alg
Normal file
4
Task/Character-codes/ALGOL-68/character-codes-1.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
main:(
|
||||
printf(($gl$, ABS "a")); # for ASCII this prints "+97" EBCDIC prints "+129" #
|
||||
printf(($gl$, REPR 97)) # for ASCII this prints "a"; EBCDIC prints "/" #
|
||||
)
|
||||
4
Task/Character-codes/ALGOL-68/character-codes-2.alg
Normal file
4
Task/Character-codes/ALGOL-68/character-codes-2.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
FILE tape;
|
||||
INT errno = open(tape, "/dev/tape1", stand out channel)
|
||||
make conv(tape, ebcdic conv);
|
||||
FOR record DO getf(tape, ( ~ )) OD; ~ # etc ... #
|
||||
1
Task/Character-codes/ALGOL-68/character-codes-3.alg
Normal file
1
Task/Character-codes/ALGOL-68/character-codes-3.alg
Normal file
|
|
@ -0,0 +1 @@
|
|||
make conv(tape, stand conv(stand out channel))
|
||||
13
Task/Character-codes/AWK/character-codes.awk
Normal file
13
Task/Character-codes/AWK/character-codes.awk
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
function ord(c)
|
||||
{
|
||||
return chmap[c]
|
||||
}
|
||||
BEGIN {
|
||||
for(i=0; i < 256; i++) {
|
||||
chmap[sprintf("%c", i)] = i
|
||||
}
|
||||
print ord("a"), ord("b")
|
||||
printf "%c %c\n", 97, 98
|
||||
s = sprintf("%c%c", 97, 98)
|
||||
print s
|
||||
}
|
||||
2
Task/Character-codes/ActionScript/character-codes.as
Normal file
2
Task/Character-codes/ActionScript/character-codes.as
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
trace(String.fromCharCode(97)); //prints 'a'
|
||||
trace("a".charCodeAt(0));//prints '97'
|
||||
6
Task/Character-codes/Ada/character-codes.ada
Normal file
6
Task/Character-codes/Ada/character-codes.ada
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Char_Code is
|
||||
begin
|
||||
Put_Line (Character'Val (97) & " =" & Integer'Image (Character'Pos ('a')));
|
||||
end Char_Code;
|
||||
6
Task/Character-codes/Aime/character-codes.aime
Normal file
6
Task/Character-codes/Aime/character-codes.aime
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# prints "97"
|
||||
o_integer('a');
|
||||
o_byte('\n');
|
||||
# prints "a"
|
||||
o_byte(97);
|
||||
o_byte('\n');
|
||||
2
Task/Character-codes/AutoHotkey/character-codes.ahk
Normal file
2
Task/Character-codes/AutoHotkey/character-codes.ahk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
MsgBox % Chr(97)
|
||||
MsgBox % Asc("a")
|
||||
4
Task/Character-codes/BASIC/character-codes-1.bas
Normal file
4
Task/Character-codes/BASIC/character-codes-1.bas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
charCode = 97
|
||||
char = "a"
|
||||
PRINT CHR$(charCode) 'prints a
|
||||
PRINT ASC(char) 'prints 97
|
||||
4
Task/Character-codes/BASIC/character-codes-2.bas
Normal file
4
Task/Character-codes/BASIC/character-codes-2.bas
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
10 LET c = 97: REM c is a character code
|
||||
20 LET d$ = "b": REM d$ holds the character
|
||||
30 PRINT CHR$(c): REM this prints a
|
||||
40 PRINT CODE(d$): REM this prints 98
|
||||
4
Task/Character-codes/BBC-BASIC/character-codes.bbc
Normal file
4
Task/Character-codes/BBC-BASIC/character-codes.bbc
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
charCode = 97
|
||||
char$ = "a"
|
||||
PRINT CHR$(charCode) : REM prints a
|
||||
PRINT ASC(char$) : REM prints 97
|
||||
1
Task/Character-codes/Befunge/character-codes.bf
Normal file
1
Task/Character-codes/Befunge/character-codes.bf
Normal file
|
|
@ -0,0 +1 @@
|
|||
"A". 88*1+,
|
||||
7
Task/Character-codes/C++/character-codes.cpp
Normal file
7
Task/Character-codes/C++/character-codes.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::cout << (int)'a' << std::endl; // prints "97"
|
||||
std::cout << (char)97 << std::endl; // prints "a"
|
||||
return 0;
|
||||
}
|
||||
7
Task/Character-codes/C/character-codes.c
Normal file
7
Task/Character-codes/C/character-codes.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
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;
|
||||
}
|
||||
6
Task/Character-codes/Clojure/character-codes.clj
Normal file
6
Task/Character-codes/Clojure/character-codes.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(print (int \a)) ; prints "97"
|
||||
(print (char 97)) ; prints \a
|
||||
|
||||
; Unicode is also available, as Clojure uses the underlying java Strings & chars
|
||||
(print (int \π)) ; prints 960
|
||||
(print (char 960)) ; prints \π
|
||||
2
Task/Character-codes/CoffeeScript/character-codes.coffee
Normal file
2
Task/Character-codes/CoffeeScript/character-codes.coffee
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
console.log 'a'.charCodeAt 0 # 97
|
||||
console.log String.fromCharCode 97 # a
|
||||
2
Task/Character-codes/Common-Lisp/character-codes.lisp
Normal file
2
Task/Character-codes/Common-Lisp/character-codes.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(princ (char-code #\a)) ; prints "97"
|
||||
(princ (code-char 97)) ; prints "a"
|
||||
13
Task/Character-codes/D/character-codes.d
Normal file
13
Task/Character-codes/D/character-codes.d
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import std.stdio, std.utf;
|
||||
|
||||
void main() {
|
||||
string test = "a";
|
||||
size_t index = 0;
|
||||
|
||||
// Get four-byte utf32 value for index 0
|
||||
// this returns dchar, so cast it to numeric.
|
||||
writeln(cast(uint)test.decode(index));
|
||||
|
||||
// 'index' has moved to next character position in input.
|
||||
assert(index == 1);
|
||||
}
|
||||
2
Task/Character-codes/DWScript/character-codes.dwscript
Normal file
2
Task/Character-codes/DWScript/character-codes.dwscript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
PrintLn(Ord('a'));
|
||||
PrintLn(Chr(97));
|
||||
19
Task/Character-codes/Delphi/character-codes.delphi
Normal file
19
Task/Character-codes/Delphi/character-codes.delphi
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
program Project1;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
var
|
||||
aChar:Char;
|
||||
aCode:Byte;
|
||||
uChar:WideChar;
|
||||
uCode:Word;
|
||||
begin
|
||||
aChar := Chr(97); Writeln(aChar);
|
||||
aCode := Ord(aChar); Writeln(aCode);
|
||||
uChar := WideChar(97); Writeln(uChar);
|
||||
uCode := Ord(uChar); Writeln(uCode);
|
||||
|
||||
Readln;
|
||||
end.
|
||||
5
Task/Character-codes/E/character-codes.e
Normal file
5
Task/Character-codes/E/character-codes.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
? 'a'.asInteger()
|
||||
# value: 97
|
||||
|
||||
? <import:java.lang.makeCharacter>.asChar(97)
|
||||
# value: 'a'
|
||||
8
Task/Character-codes/Elena/character-codes.elena
Normal file
8
Task/Character-codes/Elena/character-codes.elena
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#define std'dictionary'*.
|
||||
#define std'basic'*.
|
||||
|
||||
#symbol Program =>
|
||||
[
|
||||
'program'output << WideCharVar::"a" numeric.
|
||||
'program'output << WideCharVar::97.
|
||||
].
|
||||
4
Task/Character-codes/Erlang/character-codes-1.erl
Normal file
4
Task/Character-codes/Erlang/character-codes-1.erl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
1> F = fun([X]) -> X end.
|
||||
#Fun<erl_eval.6.13229925>
|
||||
2> F("a").
|
||||
97
|
||||
2
Task/Character-codes/Erlang/character-codes-2.erl
Normal file
2
Task/Character-codes/Erlang/character-codes-2.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
3> $a.
|
||||
97
|
||||
2
Task/Character-codes/Euphoria/character-codes.euphoria
Normal file
2
Task/Character-codes/Euphoria/character-codes.euphoria
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
printf(1,"%d\n", 'a') -- prints "97"
|
||||
printf(1,"%s\n", 97) -- prints "a"
|
||||
3
Task/Character-codes/Forth/character-codes.fth
Normal file
3
Task/Character-codes/Forth/character-codes.fth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
char a
|
||||
dup . \ 97
|
||||
emit \ a
|
||||
2
Task/Character-codes/Fortran/character-codes.f
Normal file
2
Task/Character-codes/Fortran/character-codes.f
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
WRITE(*,*) ACHAR(97), IACHAR("a")
|
||||
WRITE(*,*) CHAR(97), ICHAR("a")
|
||||
2
Task/Character-codes/Go/character-codes-1.go
Normal file
2
Task/Character-codes/Go/character-codes-1.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fmt.Println('a') // prints "97"
|
||||
fmt.Println('π') // prints "960"
|
||||
16
Task/Character-codes/Go/character-codes-2.go
Normal file
16
Task/Character-codes/Go/character-codes-2.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// yes, there is more concise syntax, but this makes
|
||||
// the data types very clear.
|
||||
var b byte = 'a'
|
||||
var r rune = 'π'
|
||||
var s string = "aπ"
|
||||
|
||||
fmt.Println(b, r, s)
|
||||
for _, c := range s { // this gives c the type rune
|
||||
fmt.Println(c)
|
||||
}
|
||||
}
|
||||
3
Task/Character-codes/Go/character-codes-3.go
Normal file
3
Task/Character-codes/Go/character-codes-3.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
b := byte(97)
|
||||
r := rune(960)
|
||||
fmt.Printf("%c %c\n%c %c\n", 97, 960, b, r)
|
||||
3
Task/Character-codes/Go/character-codes-4.go
Normal file
3
Task/Character-codes/Go/character-codes-4.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fmt.Println(string(97)) // prints "a"
|
||||
fmt.Println(string(960)) // prints "π"
|
||||
fmt.Println(string([]rune{97, 960})) // prints "aπ"
|
||||
7
Task/Character-codes/Haskell/character-codes.hs
Normal file
7
Task/Character-codes/Haskell/character-codes.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import Data.Char
|
||||
|
||||
main = do
|
||||
print (ord 'a') -- prints "97"
|
||||
print (chr 97) -- prints "'a'"
|
||||
print (ord 'π') -- prints "960"
|
||||
print (chr 960) -- prints "'\960'"
|
||||
6
Task/Character-codes/Java/character-codes-1.java
Normal file
6
Task/Character-codes/Java/character-codes-1.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
public class Foo {
|
||||
public static void main(String[] args) {
|
||||
System.out.println((int)'a'); // prints "97"
|
||||
System.out.println((char)97); // prints "a"
|
||||
}
|
||||
}
|
||||
6
Task/Character-codes/Java/character-codes-2.java
Normal file
6
Task/Character-codes/Java/character-codes-2.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
public class Bar {
|
||||
public static void main(String[] args) {
|
||||
System.out.println((int)'π'); // prints "960"
|
||||
System.out.println((char)960); // prints "π"
|
||||
}
|
||||
}
|
||||
2
Task/Character-codes/JavaScript/character-codes.js
Normal file
2
Task/Character-codes/JavaScript/character-codes.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
document.write('a'.charCodeAt(0)); // prints "97"
|
||||
document.write(String.fromCharCode(97)); // prints "a"
|
||||
2
Task/Character-codes/Lua/character-codes.lua
Normal file
2
Task/Character-codes/Lua/character-codes.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print(string.byte("a")) -- prints "97"
|
||||
print(string.char(97)) -- prints "a"
|
||||
1
Task/Character-codes/MATLAB/character-codes-1.m
Normal file
1
Task/Character-codes/MATLAB/character-codes-1.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
character = char(asciiNumber)
|
||||
1
Task/Character-codes/MATLAB/character-codes-2.m
Normal file
1
Task/Character-codes/MATLAB/character-codes-2.m
Normal file
|
|
@ -0,0 +1 @@
|
|||
asciiNumber = double(character)
|
||||
3
Task/Character-codes/MATLAB/character-codes-3.m
Normal file
3
Task/Character-codes/MATLAB/character-codes-3.m
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
asciiNumber = uint16(character)
|
||||
asciiNumber = uint32(character)
|
||||
asciiNumber = uint64(character)
|
||||
17
Task/Character-codes/MATLAB/character-codes-4.m
Normal file
17
Task/Character-codes/MATLAB/character-codes-4.m
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
>> char(87)
|
||||
|
||||
ans =
|
||||
|
||||
W
|
||||
|
||||
>> double('W')
|
||||
|
||||
ans =
|
||||
|
||||
87
|
||||
|
||||
>> uint16('W')
|
||||
|
||||
ans =
|
||||
|
||||
87
|
||||
2
Task/Character-codes/PHP/character-codes.php
Normal file
2
Task/Character-codes/PHP/character-codes.php
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
echo ord('a'), "\n"; // prints "97"
|
||||
echo chr(97), "\n"; // prints "a"
|
||||
2
Task/Character-codes/Perl/character-codes.pl
Normal file
2
Task/Character-codes/Perl/character-codes.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print ord('a'), "\n"; # prints "97"
|
||||
print chr(97), "\n"; # prints "a"
|
||||
10
Task/Character-codes/PicoLisp/character-codes.l
Normal file
10
Task/Character-codes/PicoLisp/character-codes.l
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
: (char "a")
|
||||
-> 97
|
||||
: (char "字")
|
||||
-> 23383
|
||||
: (char 23383)
|
||||
-> "字"
|
||||
: (chop "文字")
|
||||
-> ("文" "字")
|
||||
: (mapcar char @)
|
||||
-> (25991 23383)
|
||||
2
Task/Character-codes/Python/character-codes-1.py
Normal file
2
Task/Character-codes/Python/character-codes-1.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print ord('a') # prints "97"
|
||||
print chr(97) # prints "a"
|
||||
2
Task/Character-codes/Python/character-codes-2.py
Normal file
2
Task/Character-codes/Python/character-codes-2.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print ord(u'π') # prints "960"
|
||||
print unichr(960) # prints "π"
|
||||
4
Task/Character-codes/Python/character-codes-3.py
Normal file
4
Task/Character-codes/Python/character-codes-3.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
print(ord('a')) # prints "97"
|
||||
print(ord('π')) # prints "960"
|
||||
print(chr(97)) # prints "a"
|
||||
print(chr(960)) # prints "π"
|
||||
2
Task/Character-codes/R/character-codes.r
Normal file
2
Task/Character-codes/R/character-codes.r
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ascii <- as.integer(charToRaw("hello world")); ascii
|
||||
text <- rawToChar(as.raw(ascii)); text
|
||||
14
Task/Character-codes/REXX/character-codes.rexx
Normal file
14
Task/Character-codes/REXX/character-codes.rexx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
yyy='c' /*assign a lowercase c to YYY.*/
|
||||
yyy='34'x /*assign hexadecimal 34 to YYY.*/
|
||||
/*the X can be upper/lowercase.*/
|
||||
yyy=x2c(34) /* (same as above) */
|
||||
yyy='00110100'b /* (same as above) */
|
||||
yyy='0011 0100'b /* (same as above) */
|
||||
/*the B can be upper/lowercase.*/
|
||||
yyy=d2c(97) /*assign decimal code 97 to YYY.*/
|
||||
|
||||
say yyy /*displays the value of YYY. */
|
||||
say c2x(yyy) /*displays the value of YYY in hexadecimal. */
|
||||
say c2d(yyy) /*displays the value of YYY in decimal. */
|
||||
say x2b(c2x(yyy)) /*displays the value of YYY in binary (bit string). */
|
||||
/*Note: some REXXes support the c2b bif */
|
||||
6
Task/Character-codes/Ruby/character-codes-1.rb
Normal file
6
Task/Character-codes/Ruby/character-codes-1.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> ?a
|
||||
=> 97
|
||||
> "a"[0]
|
||||
=> 97
|
||||
> 97.chr
|
||||
=> "a"
|
||||
4
Task/Character-codes/Ruby/character-codes-2.rb
Normal file
4
Task/Character-codes/Ruby/character-codes-2.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
> "a".ord
|
||||
=> 97
|
||||
> 97.chr
|
||||
=> "a"
|
||||
7
Task/Character-codes/Sather/character-codes.sa
Normal file
7
Task/Character-codes/Sather/character-codes.sa
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class MAIN is
|
||||
main is
|
||||
#OUT + 'a'.int + "\n"; -- or
|
||||
#OUT + 'a'.ascii_int + "\n";
|
||||
#OUT + CHAR::from_ascii_int(97) + "\n";
|
||||
end;
|
||||
end;
|
||||
5
Task/Character-codes/Scala/character-codes-1.scala
Normal file
5
Task/Character-codes/Scala/character-codes-1.scala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
scala> 'a' toInt
|
||||
res9: Int = 97
|
||||
|
||||
scala> 97 toChar
|
||||
res10: Char = a
|
||||
7
Task/Character-codes/Scala/character-codes-2.scala
Normal file
7
Task/Character-codes/Scala/character-codes-2.scala
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def charToInt(c: Char, next: Char): Option[Int] = (c, next) match {
|
||||
case _ if (c.isHighSurrogate && next.isLowSurrogate) => Some(java.lang.Character.toCodePoint(c, next))
|
||||
case _ if (c.isLowSurrogate) => None
|
||||
case _ => Some(c.toInt)
|
||||
}
|
||||
|
||||
def intToChars(n: Int): Array[Char] = java.lang.Character.toChars(n)
|
||||
2
Task/Character-codes/Scheme/character-codes.ss
Normal file
2
Task/Character-codes/Scheme/character-codes.ss
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(display (char->integer #\a)) (newline) ; prints "97"
|
||||
(display (integer->char 97)) (newline) ; prints "a"
|
||||
2
Task/Character-codes/Smalltalk/character-codes.st
Normal file
2
Task/Character-codes/Smalltalk/character-codes.st
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
($a asInteger) displayNl. "output 97"
|
||||
(Character value: 97) displayNl. "output a"
|
||||
6
Task/Character-codes/Tcl/character-codes.tcl
Normal file
6
Task/Character-codes/Tcl/character-codes.tcl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# ASCII
|
||||
puts [scan "a" %c] ;# ==> 97
|
||||
puts [format %c 97] ;# ==> a
|
||||
# Unicode is the same
|
||||
puts [scan "π" %c] ;# ==> 960
|
||||
puts [format %c 960] ;# ==> π
|
||||
Loading…
Add table
Add a link
Reference in a new issue