intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF (EN)

int e l 6.2 THE ASC OPERATOR EXAMPLE: >10 $(1)="ABCDEFGHIJKL" >20 FOR X=1 TO 12 >30 PRINT ASC($(1),X), >40 NEXT X >RUN 65 66 67 68 69 70 71 72 73 74 75 76 The numbers printed in the previous example are the values that represent the ASCII characters A,B,C, . . . L. Additionally, the ASC( ) operator can be used to change individual characters in a defined string. EXAMPLE: >10 $(1)="AECDEFGHIJKL" >20 PRINT $(1) >30 ASC($(1),1)=75 >40 PRINT $(1) >50 ASC($(1),2)=ASC($(1),3) >60 PRINT $(1) >RUN AECDEFGHIJKL KBCDEFGHIJKL KCCDEFGHIJKL In general, the ASC( ) operator lets the programmer manipulate individual characters in a string. A simple program can determine if two strings are identical.

EXAMPLE: >10 $(1)="SECRET" : REM SECRET IS THE PASSWORD >20 INPUT "WHAT'S THE PASSWORD - ",$(2) >30 FOR I=l TO 6 >40 IF ASC($(l),I)=ASC($(2),I) THEN NEXT I ELSE 70 >50 PRINT "YOU GUESSED IT"' >60 END >70 PRINT "WRONG. TRY AGAIN" : GOTO 20 >RUN WHAT'S THE PASSWORD - SECURE WRONG, TRY AGAIN WHAT'S THE PASSWORD - SECRET YOU GUESSED IT - 84 -