How to resolve the algorithm Character codes step by step in the Modula-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Character codes step by step in the Modula-2 programming language

Table of Contents

Problem Statement

Given a character value in your language, print its code   (could be ASCII code, Unicode code, or whatever your language uses).

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.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Character codes step by step in the Modula-2 programming language

Source code in the modula-2 programming language

MODULE asc;

IMPORT  InOut;

VAR     letter          : CHAR;
        ascii           : CARDINAL;

BEGIN
  letter := 'a';
  InOut.Write (letter);
  ascii := ORD (letter);
  InOut.Write (11C);            (*  ASCII TAB   *)
  InOut.WriteCard (ascii, 8);
  ascii := ascii - ORD ('0');
  InOut.Write (11C);            (*  ASCII TAB   *)
  InOut.Write (CHR (ascii));
  InOut.WriteLn
END asc.


jan@Beryllium:~/modula/rosetta$ ./asc
a             97        1

  

You may also check:How to resolve the algorithm Determine if a string is numeric step by step in the Elixir programming language
You may also check:How to resolve the algorithm Enforced immutability step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Padovan n-step number sequences step by step in the Phix programming language
You may also check:How to resolve the algorithm Hailstone sequence step by step in the Elena programming language
You may also check:How to resolve the algorithm Program termination step by step in the GW-BASIC programming language