Base Function

Purpose

Returns a string representing a number using a specific base.

Syntax

string = Base[$](value [, :] radix)

value: iexp
radix: character (0 - 9, A - Z)

string = Base$(& radix : value, newradix)

value: word
radix, newradix: character (0 - 9, A - Z)

Description

Base$() converts the digits of value to a character string and stores the result (up to 33 bytes) in string. The radix argument specifies the base of value, which must be a character in the range 0 - 9 and A - Z. For example:

Print Base$(21286:Z) // prints GFA

Print Base$(21286:9) // prints 21286

When used in this way, where a numeric value is separated with a colon and followed with a radix, the radix is limited to 2-9 and A-Z.

When used with comma, radix may be chosen from 2-36. For example

Print Base$(21286, 2// prints 101001100100110

Print Base$(21286, 8// prints 51446

Print Base$(21286, 10) // prints 21286

Print Base$(21286, 16) // prints 5326

These are the general forms for Bin$(), Oct$() Dec$(), and Hex$().

To convert a word into a number the following format is used:

Base$(& radix : word, newradix)

radix specifies the base of the word that is to be converted to newradix. newradix can be any character between 0-9 and A-Z, but it can also be a number in the range from 0-36. For instance, the radix Z equals ',36'.

Example

OpenW # 1

Print Base$(21286:Z)    // prints GFA

// The inverse...

Print Base$(&Z:GFA, 10) // prints 21286

See Also

Bin$, Oct$, Dec$, Hex$

{Created by Sjouke Hamstra; Last updated: 24/09/2014 by James Gaite}