How to resolve the algorithm Character codes step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Character codes step by step in the CLU 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 CLU programming language

Source code in the clu programming language

start_up = proc ()
    po: stream := stream$primary_output()
    
    % To turn a character code into an integer, use char$c2i
    % (but then to print it, it needs to be turned into a string first
    % with int$unparse)
    stream$putl(po, int$unparse( char$c2i( 'a' ) ) ) % prints '97' 
    
    % To turn an integer into a character code, use char$i2c
    stream$putc(po, char$i2c( 97 ) );  % prints 'a'
end start_up

  

You may also check:How to resolve the algorithm Fibonacci word step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Excel programming language
You may also check:How to resolve the algorithm Pythagorean triples step by step in the ERRE programming language
You may also check:How to resolve the algorithm Find the last Sunday of each month step by step in the Scala programming language
You may also check:How to resolve the algorithm Approximate equality step by step in the Sidef programming language