Skip to content

BASIC Numeric and String Literals

Curtis F Kaylor edited this page Nov 25, 2023 · 7 revisions

Numeric and String Literals

Integer literals

Integer literals are whole numbers (numbers without decimal points).

Integer literals must be between -65535 and +65535. Integer literals do not have decimal points or commas between digits. If the plus (+) sign is left out, the literal is assumed to be a positive number. Zeros coming before a literal are ignored and shouldn't be used since they waste memory and slow down your program, but won't cause an error. Integers are stored in memory as two-byte binary numbers.

Some examples of integer literals are:

  • -12
  • 8765
  • -32768
  • +44
  • 0
  • -32767

NOTE: Do NOT put commas inside any number. For example, always type 32,000 as 32000. If you put a comma in the middle of a number you will get the BASIC error message ?SYNTAX ERROR.

Advanced: Integers are stored in memory as Floating-Point Numbers.

plusBASIC enhancements

Hexadecimal literals

Hexadecimal literals consist of a dollar sign followed a series of hexadecimal digits

The hexadecimal number must be between $0 and $FFFF (0 through 65525). Any number of zero is allowed directly after the dollar sign, but they will slow down your program.

Some examples of Hexadecimal integer literals are:

  • $42
  • $00A
  • $8123
  • $C002
  • $FFFF

ASCII literals

ASCII literals evaluate to the ASCII value of a single character.

An ASCII literal consists of a single quote, a single character, and another single quote. Both the start and end quote must be there, and must be one and only one character between them. Any printable character is allowed, even a single quote.

Some examples of ASCII literals are:

  • ' '
  • '0'
  • '''
  • '@'
  • 'z'

Note: 'x' is functionally identical to ASC("x").

String literals

String literals are groups of alphanumeric information like letters, numbers, and symbols.

A string literal can have any length up to the space available in a 72-character line (that is, any character spaces not taken up by the line number and other required parts of the statement).

A string literal can contain blanks, letters, numbers, and punctuation. The double quote mark (") character cannot be included in a string because it is used to define the beginning and end of the string. A string can also have a null value-which means that it can contain no character data. You can leave the ending quote mark off of a string if it's the last item on a line.

Some examples of string literals are:

  • "" a null string
  • "HELLO"
  • "$25,000.00"
  • "NUMBER OF EMPLOYEES"

plusBASIC enhancements

Hexadecimal string literals

A hexadecimal string is a series of hexadecimal numbers representing the ASCII characters in the string.

A hexadecimal string literal consists of a dollar sign $, an opening quotation mark ", an even number of hexadecimal digits, and a closing quotation mark ".

Each pair of hexadecimal digits corresponds to a single ASCII character of the resulting string.

Some examples of hexadecimal string literals are:

  • $"" - a null string
  • $"07" Ctrl-G, which cause a beep when printed
  • $"00" - ASCII code 0, the pound sterling £
  • $"05" - ASCII code 5, the copyright symbol ©
  • $"9E8e" - Left pointing and right pointing triangles, and

NOTE: Hexadecimal string literals are the only string literals that may contain embedded ASCII 0 characters

Escaped string literals

An escaped string literal contains one or more escape sequences representing specific ASCII characters.

An escaped string literal consists of a backslash \, opening quotes ", a series of typeable characters, and closing quotes ".

Escape sequences consisting of a backslash \ followed by a special character are used to represent special ASCII characters in the string.

-- Sequence -- Name -- ASCII -- Action
\a Bell 7 Beep
\b Backspace 8 Move cursor left
\n Newline 13 and 10 Move cursor to beginning of next line
\v Vertical Tab 11 Clear the screen
\xHH Hex Code special A character with ASCII code equal to the two hex digits after the x
\" Quotes 34 The quotation mark character "
\\ Backlash 92 The backslash character \

A backslash followed by any other character resolves to that character.

Some examples of escaped string literals are:

  • \"Beep\aBeep\a" - Displays as BeepBeep and makes the computer beep twice
  • \"Backs\bSpace" Displays as BackSpace
  • \"Back\\Slash" - Displays as Back\Slash
  • \"\"quoted\"" - Displays as "quoted"
  • \"1\x01" - Displays as
Clone this wiki locally