Not expandably, of course:
\def\achar#1{\begingroup\lccode`!=#1\lowercase{\endgroup!}}
\achar{65}
\achar{`A}
\achar{"41}
will give
A A A
But of course
\char<number>
does the same. The \achar technique can be useful if you want to define a macro to expand to the character given by number (with category code 12):
\def\achar#1#2{\begingroup\lccode`!=#2\lowercase{\endgroup\def#1{!}}}
\achar\firstA{65}
\achar\secondA{`A}
\achar\thirdA{"41}
\show\firstA \show\secondA \show\thirdA
What does \achar do? It starts a group where the lowercase correspondent of the exclamation character is set to character #2 (which is supposed to be a number, in any of the formats TeX allows for specifying an integer constant). This correspondance is maintained by an array (a 256 component vector, in 8 bit TeX, the whole 0x110000 of Unicode for XeTeX and LuaTeX, from 0x0000 to 0x10FFFF): the n-th entry specifies the lowercase correspondent for character number n.
When we say \lowercase{<tokens>}, TeX performs the substitution of each character token with its lowercase correspondent and then inserts back in the input stream the token list so obtained, to be read again. In our case \endgroup, \def and the first argument to \achar are not touched, as they are not character tokens, so only ! is converted, exactly to the character having the number we specified in the second argument. Notice that TeX still hasn't executed \endgroup: it does only when the token list is put back. So the group is closed, the \lccode assignment is forgotten and the \def is executed.
With \achar\firstA{65}, for example, the replacement text for \firstA is A with category code 12, because ! has category code 12 and \lowercase doesn't change this attribute.
The LaTeX3 code is just the same:
\NewDocumentCommand { \achar } { m m }
{
\group_begin:
\char_set_lccode:nn { `! } { #2 }
\tl_to_lowercase:n { \group_end: \cs_new:Npn #1 { ! } }
}
\char_value_catcode:n { `#1 }instead of\char_value_catcode:n { #1 }. – Bruno Le Floch Feb 9 '12 at 18:36\tex_number:DA`. This will print65. But I want to insert65and want to getA. (LaTeX3 solution isn't deprecated ;-) ). Please provide an answer. – Marco Daniel Feb 9 '12 at 18:40