Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 36
Case Shifting Character Strings
The following example reads some ASCII input from a terminal. The input is expected
to be numeric data so the DNUMIN procedure is used to convert the number from
ASCII representation into a binary number.
BASE := 10;
!Read from the terminal into the input buffer:
CALL READX(TERMNUM,SBUFFER,BUFSIZE,COUNT^READ);
IF <> THEN ... !file-system error
!Set the next byte in the buffer to zero to make sure that
!DNUMIN recognizes the end of the numeric string
SBUFFER[COUNT^READ] := 0;
@NEXT^ADDR := DNUMIN(SBUFFER, !numeric ASCII code
SIGNED^RESULT, !32-bit result
BASE, !numeric base of input
STATUS); !status of conversion
!Check that the value of STATUS is zero and that DNUMIN
!converted the expected number of characters:
IF STATUS OR @NEXT^ADDR <> @SBUFFER[COUNT^READ]
THEN ... !invalid number
Converting a Binary Number Into an ASCII String
To convert a binary number into an ASCII string, you use either the NUMOUT or
DNUMOUT procedure. For a 16-bit integer, you use the NUMOUT procedure. For a
32-bit integer, you use the DNUMOUT procedure.
To use the NUMOUT procedure, you must supply the 16-bit binary integer that you
want to convert, along with the numeric base you require for the ASCII number and the
maximum number of characters you permit in the output. The numeric base must be in
the range 2 through 10. The NUMOUT procedure returns the ASCII result. An
example follows:
BASE := 10;
WIDTH := 4;
CALL NUMOUT(ASCII^RESULT, !output string
UNSIGNED^INTEGER, !binary input
BASE, !numeric base of output
WIDTH); !maximum number of
!characters in output
Case Shifting Character Strings
You should use the SHIFTSTRING procedure to perform all case-shifting operations on
alphabetic characters. This procedure enables you to perform case shifting from
lowercase to uppercase and from uppercase to lowercase.
The standard ASCII character set allows you to shift case by inverting the fifth bit from
the right of any alphabetic character. However, not every local character set uses this
mechanism for case shifting. You are therefore encouraged to use the SHIFTSTRING
procedure, which is configured to work with the locally supported character set.