Ordinal Functions [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation
HP Pascal/iX Reference Manual
Ordinal Functions
The ordinal functions found in HP Pascal are chr, ord, pred, and succ.
Each of these functions are discussed on the next few pages.
chr
Usage
chr(x)
Argument
x An integer expression in the range 0..255.
Description
The chr function converts an integer numeric value into an ASCII
character by returning the character value, if any, whose ordinal number
is equal to the value of its argument. Note that it is an error if the
argument is not within the range 0..255.
Example
Input Result
chr(x) depends on the value of x
chr(63) '?'
chr(82) 'R'
chr(13) (carriage return)
ord
Usage
ord(x)
Argument
x An ordinal expression.
Description
The function ord(x) returns the integer representing the ordinal
associated with the value of x. If x is an integer, x itself is
returned. If x is type char, the result is an integer value between 0
and 255 determined by the ASCII order sequence. If x is any other
ordinal type (such as a predefined or user-defined enumerated type), then
the result is the ordinal number determined by mapping the values of the
type onto consecutive non-negative integers star ting at zero. For
example, since the standard type Boolean is predefined as:
TYPE Boolean = (false,true)
The call ord (false) returns 0, and the call ord (true) returns 1.
For any character ch, the following is true:
chr (ord (ch)) = ch
It is an error if the result is greater than maxint or less than minint.
Example
Input Result
ord(ord_exp) depends on the value of ord_exp
ord('a') 97
ord('A') 65
ord(-1) -1
ord(yellow) 2 {TYPE color=(red,blue,yellow)}
ord(red) 0
NOTE Taking the ORD of short pointer type expressions is permitted at
the Standard_Level EXT_MODCAL.
pred
Usage
pred(n)
Argument
x Any ordinal expression.
Description
The pred function returns the value whose ordinal number is one less than
the ordinal number of the argument. The type of the result is identical
to the type of the argument. pred(x) must exist.
Example
Input Result
pred(ord_var) depends on the value of ord_var
pred(1) 0
pred(-5) -6
pred('B') 'A'
pred(true) false
pred(false) {error}
succ
succ(x)
Argument
x Any ordinal expression.
Description
The succ function returns the value whose ordinal number is one greater
than the ordinal number of the argument. The type of the result is
identical with the type of the argument. It is an error if succ(x) does
not exist.
Example
Input Result
succ(ord('b')) 99
succ(1) 2
succ(-5) -4
succ('a') 'b'
succ(false) true
succ(true) { error }
MPE/iX 5.0 Documentation