Requirements:
You need to convert a character (ASCII or Unicode) to a digital encoding.
Or vice versa.
Discussion
:
For ASCII characters, you can use the built-in ord and CHR methods to achieve the following requirements:
>>> CHR (97)
'A'
>>> Ord ('A ')
97
For Unicode characters, ORD and repr must be used.
To obtain Unicode characters, use unichr:
>>> Print ord (U'/u2020 ')
8224
>>> Print repr (unichr (8224 ))
U'/u2020'
Instructions:
The following is a brief description of these methods in Python:
Ord (...)
Ord (c)-> integer
Return the integer ordinal of a One-character string.
CHR (...)
CHR (I)-> character
Return a string of one character with ordinal I; 0 <= I <256.
Repr (...)
Repr (object)-> string
Return the canonical string representation of the object.
For most object types, Eval (Repr (object) = object.
Unichr (...)
Unichr (I)-> Unicode Character
Return a unicode string of one character with ordinal I; 0 <= I <= 0x10ffff.