Skip to content

The ord() Command

Command Summary Command Syntax Calculator Compatibility Token Size
Gives the ASCII code of a character. ord(string) This command works on all calculators. 2 bytes
  • Press 2nd MATH to enter the MATH popup menu.
  • Press D to enter the string submenu.
  • Press B to select ord(.

The ord() Command

The ord() command gives the ASCII code of a character (that is, its character code, which is a modification of standard ASCII). The input is meant to be a single character, but the command doesn't actually check for that — so in practice, it gives the ASCII code of the first character in a string. You can convert multiple characters at once by giving ord() a list (or matrix) of characters.

The inverse of ord() is 68k:char(), which converts a character code to a character.

:ord("America")
           65
:ord({"A","b","c"})
           {65  98  99}
:ord("")
           0

Optimization

Code such as

:inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",str)

should be replaced by appropriate use of ord(); in this case,
:ord(str)-64

See Also

Authors: KG