

Task

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



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.




/* NetRexx */
options replace format comments java crossref symbols nobinary
 
runSample(arg)
return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
  -- create some sample data: character, hex and unicode
  samp = ' ' || 'a'.sequence('e') || '$' || '\xa2'.sequence('\xa5') || '\u20a0'.sequence('\u20b5')
  -- use the C2D C2X D2C and X2C built-in functions
  say "'"samp"'"
  say '   | Chr    C2D  C2X D2C X2C'
  say '---+ --- ------ ---- --- ---'
  loop ci = 1 to samp.length
    cc = samp.substr(ci, 1)
    cd = cc.c2d -- char to decimal
    cx = cc.c2x -- char to hexadecimal
    dc = cd.d2c -- decimal to char
    xc = cx.x2c -- hexadecimal to char
    say ci.right(3)"| '"cc"'" cd.right(6) cx.right(4, 0) "'"dc"' '"xc"'"
    end ci
  return