ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Strings & arrays/ASC and CHR
J277 · 2.2.3

Unit 8 · Lesson 3

ASC and CHR

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Use OCR ASC/CHR and Python ord()/chr() in short string-processing programs.

ASC() converts one character into its numeric code, while CHR() performs the reverse conversion. Python calls these functions ord() and chr(). For the standard examples, A has code 65 and code 97 represents lowercase a.

Character code

A number used by a computer to represent a character.

ASC()

The OCR ERL operation that returns the numeric code of a character.

CHR()

The OCR ERL operation that returns the character represented by a numeric code.

ord() / chr()

The Python functions corresponding to OCR ASC() and CHR().

Keep these in mind

  • OCR ASC(character) maps to Python ord(character).
  • OCR CHR(number) maps to Python chr(number).
  • ASC returns a number; CHR returns one character.
  • A code can be adjusted with arithmetic before converting it back to a character.

Learning objective

Use OCR ASC/CHR and Python ord()/chr() in short string-processing programs.

Exam tip

Check the conversion direction from the required result type: a requested number needs ASC/ord, while a requested character needs CHR/chr.

Common mistake

CHR('A') and ord(65) reverse the argument types. Characters go into ASC/ord; integer codes go into CHR/chr.

PreviousNext