Converting Between ASCII Characters and Values
You want to get the number representing the ASCII value of a
character, or you want to display the characters associated with
a particular ASCII numerical value.
The built in function
char->integer converts a character to
an extended ASCII value (i.e., a number in the range of 0 to 255), while
integer->char takes an extended ASCII value and returns
the corresponding character.
> (char->integer #\C)
67
> (integer->char 68)
#\D
The procedures
char->latin-1-integer and
latin-1-integer->char
support conversions between characters in the platform-specific
character set and platform-independent Latin-1 (ISO 8859-1) values:
> (char->latin-1-integer #\U)
85
> (latin-1-integer->char 241)
#\ñ
Character values are "extended ASCII" values from 0 to 255 (where the ASCII extensions are platform-specific). If
integer->char is given an integer that is not in 0 to 255 inclusive, the
exn:application:type exception is raised.
char->latin-1-integer returns the integer in 0 to 255 inclusive corresponding to the Latin-1 value for char, or
#f if char (in the platform-specific character set) has no corresponding character in Latin-1.
latin-1-integer->char returns the character corresponding to the Latin-1 mapping of its input, or
#f if the platform-specific character set does not support the corresponding Latin-1 character. If the input is not in 0 to 255 inclusive, the
exn:application:type exception is raised.
For Unix and Mac OS,
char->latin-1-integer and
latin-1-integer->char are the same as
char->integer and
integer->char. For Windows, the platform-specific set and Latin-1
match except for the range
#x80 to
#x9F (which are unprintable
control characters in Latin-1).