Character codes: Difference between revisions

→‎{{header|ALGOL 68}}: Ada solution added
m (→‎[[Character code#ALGOL 68]]: character conversion routines)
(→‎{{header|ALGOL 68}}: Ada solution added)
Line 3:
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.
 
=={{header|Ada}}==
<ada>
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;
</ada>
The predefined language attributes S'Pos and S'Val for every discrete subtype, and Character is such a type, yield the position of a value and value by its position correspondingly. Sample output.
<pre>
a = 97
</pre>
=={{header|ALGOL 68}}==
In ALGOL 68 the FORMAT $g$ is type aware, hence the type conversion operators ABS & REPR are used to set the type.