The ord() Command

ord.png

Command Summary

Gives the ASCII code of a character.

Command Syntax

ord(string)

Menu Location

  • Press 2nd MATH to enter the MATH popup menu.
  • Press D to enter the string submenu.
  • Press B to select ord(.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes

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 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

Related Commands

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License