Converting Strings And Numbers - Commodore 128 System Manual

Hide thumbs Also See for 128:
Table of Contents

Advertisement

Each number generated represents one toss of a die. To simulate
a pair of dice, use two commands of this nature. Each number is
generated separately, and the sum of the two numbers
represents the total of the dice.
The ASC and CHR$ Functions
Every character that the Commodore 128 can display (including
graphic characters) has a number assigned to it. This number is
called a character string code (CHR$) and there are 255 of them
in the Commodore 128. There are two functions associated with
this concept that are very useful. The first is the ASC function.
Type:
? ASC(" Q") RETURN
The computer responds with 81. 81 is the character string code
for the Q key. Substitute any key for Q in the command above to
find out the Commodore ASCII code number for any character.
The second function is the CHR$ function. Type:
?CHR$(81)
The computer responds with Q. ln effect, the CHR$ function is
the opposite of the ASC function. They both refer to the table of
character string codes in the computer's memory. CHR$ values
can be used to program function keys. See Section 5 for more
information about this use of CHR$. See Appendix E of this Guide
for a listing of ASC and CHR$ codes.

Converting Strings and Numbers

Sometimes you may need to perform calculations on numeric
characters that are stored as string variables in your program.
Other times, you may want to perform string operations on
numbers. There are two BASIC functions you can use to convert
your variables from numeric to string type and vice versa.
4-22
RETURN

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents