Available on: all targets
See also: CHR

ASC

The ASC command performs a very specific function: it converts the first character of a string into its corresponding ASCII code. ASCII stands for American Standard Code for Information Interchange and it is a standard encoding that associates each alphanumeric character and many symbols with an integer between 0 and 127. This number represents the internal representation of the character within the computer.

The ASC command allows you to manipulate the individual characters of a string numerically. For example, you can check whether a character is an uppercase letter (its ASCII code will be between 65 and 90), or whether it is a number (its ASCII code will be between 48 and 57).

Comparing the ASCII codes of two characters is an efficient way to establish the alphabetical order between them and, in some applications, you need to convert characters to numbers or vice versa. ASC is a fundamental tool for this type of operation.

In 8-bit computers, memory is organized in bytes, which are sequences of 8 bits. Each byte can represent a number from 0 to 255. Since ASCII encoding uses only 7 bits, a byte can represent 128 different characters. On 8-bit computers, the supported character set is limited to 128 ASCII characters. This means that accented characters or characters from other languages cannot be directly represented. The exact meaning of an ASCII code can vary slightly depending on the encoding used. Note that the CHR$ command is the inverse of ASC, it converts an ASCII code to a character.

SYNTAX

 = ASC( string )


Legend
  • id : identifier
  • type : datatype
  • v : value
  • "..." : string
  • [...] : optional

EXAMPLE

 x = ASC( "UGBASIC" )


Used in:

ABBREVIATION: Ax

Join BASIC 10Liner Contest with ugBASIC!

An interesting competition is held at the beginning of each year: the BASIC 10Liner Contest. It is possible to use ugBASIC to participate in the next "BASIC10Liner" competition, in the following categories:

  • PUR-120 - A game in 10 lines of max 120 characters (w/abbrev.)
  • EXTREME-256 - A game in 10 lines of max 256 characters (w/abbrev.)
  • SCHAU - Any program in 10 lines of max 256 characters (w/abbrev.)
In order to reduce space you can use this abbreviation for this instruction:

ASC ↔ Ax

Any problem?

If you have found a problem with this keyword, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub.
Thank you!

open an issue BACK TO KEYWORDS