Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 35
Manipulating Character Strings
Manipulating Character Strings
Without using the formatter, there are several operations that you can perform on
character strings:
Convert a string of ASCII numeric characters into a binary number (NUMIN and
DNUMIN procedures) or convert a binary number into an ASCII string for output
(NUMOUT and DNUMOUT procedures). See Converting Between Strings and
Integers later in this subsection.
Change lowercase alphabetic characters into uppercase or change uppercase
alphabetic characters into lowercase (SHIFTSTRING procedure). Case Shifting
Character Strings describes how to do this.
Edit a string (FIXSTRING procedure). See Editing a Character String.
Sort characters in memory (HEAPSORT[X_] procedure). See Sorting Characters.
Converting Between Strings and Integers
Numeric input and output to a terminal is done using standard 7-bit ASCII codes.
Internally, numeric representation takes the form of binary numbers. You therefore
need to convert from ASCII to binary numeric representation on input and from binary
to ASCII representation on output.
One way of converting between ASCII and binary numeric representation is to use the
formatter as described in the previous subsection. The formatter can perform this
conversion for any numeric type. For single-length and double-length integers,
however, you can use the NUMIN, DNUMIN, NUMOUT, and DNUMOUT procedures.
The following paragraphs describe how.
Converting a Numeric ASCII String Into a Binary Number
To convert a numeric ASCII string into a binary number, you use either the NUMIN or
DNUMIN procedure. For a 16-bit result, you use the NUMIN procedure. For a 32-bit
result, use the DNUMIN procedure.
You must supply the ASCII number that you want to convert, along with the numeric
ba
se of the ASCII number. The numeric base must be in the range 2 through 10 for
NUMIN or 2 through 36 for DNUMIN. NUMIN or DNUMIN recognizes the end of the
numeric string by the first nonnumeric or zero character in the input buffer.
The NUMIN procedure returns the signed 16-bit result and a status indication showing
whether the conversion was successful. DNUMIN provides the same information as
NUMIN except that the result is 32 bits. Both procedures also return the address of the
first character after the input string. You can use this value to check that the procedure
converted the expected number of characters.