base

operator

Return type:
Integer
Returns:
A number.
Syntax
string-expression base numeric-expression


Purpose

Used to convert a string representation of a non-decimal number into a numeric value.

The first operand in the syntax is a string representation of the number in the specified base (octal, hexadecimal, etc.). Letters (either uppercase or lowercase) are used to represent digits higher than 9. For instance, hexadecimal (base 16) numbers consist of the digits "0123456789abcdef". Octal numbers (base 8) consist only of "01234567".

The second operand in the syntax is the radix, which must be between 2 and 36, inclusive.

If a character in the string expression is not a valid digit in the specified base, an error occurs. For example, the expression "16a" BASE 10 would cause an error, because "a" is not a valid digit in the base 10 system.

The following code illustrates the use of the base operator in converting a string representation of a non-decimal number (that is, a number that is not in base 10) into a decimal numeric value. Note that hexadecimal numbers can contain the digits and letters "01234567890abcdef". When the letters are used, they can be either uppercase or lowercase.

  find [digit | "ABCDEFabcdef"]+ => hex-location
     local integer location
     set location to hex-location base 16

Related Concepts