Character codes: Difference between revisions

m
→‎{{header|REXX}}: re-wrote the REXX program with more displays and more comments.
No edit summary
m (→‎{{header|REXX}}: re-wrote the REXX program with more displays and more comments.)
Line 1,086:
 
=={{header|REXX}}==
REXX supports handling of characters with built-in functions (BIFs), whether it be hexadecimal, binary (bits), or decimal codescode(s).
===version 1 ASCII ===
<lang rexx>yyy='c' /*REXX program displays a char's ASCII code/*assignvalue a(or lowercaseEBCDIC if run con toan EBCDIC YYY.system)*/
yyy= '34c'x /*assign hexadecimala lowercase c 34 to YYY. */
yyy= "c" /*the (same as above) X can be upper/lowercase.*/
say 'from char, yyy code=' yyy
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= '63'x /*displays the value of YYY. /*assign hexadecimal 63 to YYY. */
say c2x(yyy)= '63'X /*displays the(same as above) value of YYY in hexadecimal. */
say 'from hex, yyy code=' yyy
say c2d(yyy) /*displays the value of YYY in decimal. */
 
say x2b(c2x(yyy)) /*displays the value of YYY in binary (bit string). */
yyy= x2c(63) /*Note:assign hexadecimal some REXXes support the 63 c2b bif to YYY. */</lang>
say 'from hex, yyy code=' yyy
===version 2 EBCDIC ===
 
yyy= '01100011'b /*assign a binary 0011 0100 to YYY. */
yyy=x2c(34) '0110 0011'b /* (same as above) */
yyy= '0110 0011'B /* " " " */
say 'from bin, yyy code=' yyy
 
yyy= d2c(9799) /*assign decimal code 97 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) /*displays the value of YYY in decimal. */
say ' bin code: ' x2b( c2x(yyy) ) /*displays the value of YYY in binary (as a bit string). */
/*stick a fork in it, we're all done with display*/</lang>
'''output'''
<pre>
from char, yyy code= c
from hex, yyy code= c
from hex, yyy code= c
from bin, yyy code= c
from dec, yyy code= c
 
char code: c
hex code: 63
dec code: 99
bin code: 01100011
</pre>
 
===version 2 EBCDIC ===
<lang rexx>/* REXX */
yyy='c' /*assign a lowercase c to YYY */