User Tools

Site Tools


ugbasic:user:kw:asc
Translations of this page:


ugBASIC User Manual

ASC ✓

SYNTAX

   = ASC( string )

PURPOSE

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.

EXAMPLE

  x = ASC( "UGBASIC" )

See also the following example files:

ABBREVIATION

 Ax

AVAILABLE ON

  • Atari (400/800)
  • Atari XL/XE
  • Commodore 128 (MOS 8502)
  • Commodore 128 (Zilog Z80)
  • Commodore 64
  • Commodore 64+REU
  • TRS-80 Color Computer
  • TRS-80 Color Computer 3
  • ColecoVision
  • Amstrad CPC 664
  • Dragon 32
  • Dragon 64
  • Thomson MO5
  • Thomson MO5
  • Olivetti Prodest PC128
  • Commodore PLUS/4
  • SEGA SC-3000
  • SEGA SG-1000
  • VG-5000
  • Commodore VIC-20
  • ZX Spectrum 48

SEE ALSO

CHR

ANY PROBLEM?

If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!

POWERED BY