Literals
 
Non-variable compile-time string and numeric values.

Literals are numbers or strings of characters specified directly in the source code. Literals may be used to assign a variable or constant a value, passed to a procedure, or used in an expression.

Decimal, Hexadecimal, Octal, and Binary Literals


Decimal
Decimal digits ( 0 1 2 3 4 5 6 7 8 9 ). A decimal integer may be prefixed with a minus sign (-) to indicate that the number is negative.

Dim x As Integer = 123456
Dim b As Byte = -128


Hexadecimal
"&h" or "&H", followed by hexadecimal digits ( 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F )

Dim x As Integer = &h1E240
Dim b As Byte = &H80

Octal
"&o" or "&O" ( O as in Octal ), followed by octal digits ( 0 1 2 3 4 5 6 7 )

Dim x As Integer = &O361100
Dim b As Byte = &O400

Binary
"&b" or "&B", followed by binary digits ( 0 1 )

Dim x As Integer = &B11110001001000000
Dim b As Byte = &B10000000


Integer size suffixes

If an integer literal suffix is not given, the number field size required to hold the literal is automatically calculated. Specifying a size suffix guarantees that the compiler will consider a number as a specific integer size.

Integer literals ending with:
  • "l" or "L" are considered as signed 32 bit integers. (INTEGER)
  • "u", "U", "ul", or "UL", are considered as unsigned 32 bit integers. (UINTEGER)
  • "ll" or "LL", are considered as signed 64 bit integers. (LONGINT)
  • "ull" or "ULL", are considered as unsigned 64 bit integers. (ULONGINT)

Dim a As Integer = 123L
Dim b As UInteger = &h1234u
Dim c As LongInt = 76543LL
Dim d As ULongInt = &b1010101ULL


Floating Point Literals

Floating point numbers are specified in decimal digits, may be positive or negative, have a fractional portion, and optionally an exponent. The format of a floating point literal is as follows:

[-]number[.[fraction]][suffix[-|+]exponent]
or
[-].fraction[suffix[-|+]exponent]

By default, floating point numbers that do not have either an exponent or a suffix are considered as a double precision floating point value.
Dim a As Double = 123.456
Dim b As Double = -123.0


A suffix of "d", "D", "e", or "E" on the number portion indicates a double precision (64 bit total) floating point value.
Dim a As Double = -123.0d
Dim b As Double = -123.0e

An exponent may immediately follow the suffix. The exponent may be specified as either positive or negative with a plus (+) or minus (-) sign. Exponents that do not have a sign are positive.
Dim c As Double = 743.1e+13
Dim d As Double = 743.1d-13
Dim e As Double = 743.1e13


A suffix of "!", "f" or "F" on a number indicates a single precision (32 bit total) floating point value. An equivalent suffix, "#", indicates double precision. Note that an exponent cannot follow this kind of suffix.
Dim a As Single = 3.1!
Dim b As Single = -123.456e-7f
Dim c As Double = 3.14159265e3#


String Literals

String literals are a sequence of characters contained between two double quotes. The sequence of characters escaped or non-escaped.

Double quotes can be specified in the string literal by using two double quotes together.
Print "Hello World!"
Print "That's right!"
Print "See the ""word"" contained in double quotes."


String leterals can contain escape sequences if the string literal is prefixed by the ! Operator (Escaped String Literal). See Escape Sequences for a list of accepted escape sequences.
Print !"Hello\nWorld!"


By default, string literals are non-escaped unless Option Escape was used in the source in which case all string literals following are by default escaped.

A string may be explicitly specified as non-escaped when prefixed by the $ Operator (Non-Escaped String Literal).
Print $"C:\temp"


Besides ASCII files with Unicode escape sequences (\u), FreeBASIC can parse UTF-8, UTF-16LE, UTF-16BE, UTF-32LE and UTF-32BE source files allowing unicode characters directly in the string literal.

See also