How to resolve the algorithm Character codes step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Character codes step by step in the REXX 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 REXX programming language
Source code in the rexx programming language
/*REXX program displays a char's ASCII code/value (or EBCDIC if run on an EBCDIC system)*/
yyy= 'c' /*assign a lowercase c to YYY. */
yyy= "c" /* (same as above) */
say 'from char, yyy code=' yyy
yyy= '63'x /*assign hexadecimal 63 to YYY. */
yyy= '63'X /* (same as above) */
say 'from hex, yyy code=' yyy
yyy= x2c(63) /*assign hexadecimal 63 to YYY. */
say 'from hex, yyy code=' yyy
yyy= '01100011'b /*assign a binary 0011 0100 to YYY. */
yyy= '0110 0011'b /* (same as above) */
yyy= '0110 0011'B /* " " " */
say 'from bin, yyy code=' yyy
yyy= d2c(99) /*assign decimal code 99 to YYY. */
say 'from dec, yyy code=' yyy
say /* [↓] displays the value of YYY in ··· */
say 'char code: ' yyy /* character code (as an 8-bit ASCII character).*/
say ' hex code: ' c2x(yyy) /* hexadecimal */
say ' dec code: ' c2d(yyy) /* decimal */
say ' bin code: ' x2b( c2x(yyy) ) /* binary (as a bit string) */
/*stick a fork in it, we're all done with display*/
/* REXX */
yyy='c' /*assign a lowercase c to YYY */
yyy='83'x /*assign hexadecimal 83 to YYY */
/*the X can be upper/lowercase.*/
yyy=x2c(83) /* (same as above) */
yyy='10000011'b /* (same as above) */
yyy='1000 0011'b /* (same as above) */
/*the B can be upper/lowercase.*/
yyy=d2c(129) /*assign decimal code 129 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). */
You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Openscad programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the BASIC256 programming language
You may also check:How to resolve the algorithm GUI enabling/disabling of controls step by step in the Java programming language
You may also check:How to resolve the algorithm Hello world/Newbie step by step in the NS-HUBASIC programming language
You may also check:How to resolve the algorithm Call a foreign-language function step by step in the JavaScript programming language