The following built-in functions operate upon strings, converting them from one "type" to another, for example, converting a string containing a hexadecimal value into a string containing a decimal numeric string for use in math expressions. Or, you can convert a numeric string to an ASCII character, and vice versa.

B2X Converts a binary string to a hexadecimal string.
C2D Converts an ASCII character to an equivalent decimal value.
C2X Converts an ASCII character to an equivalent hexadecimal value.
D2C Converts a decimal value to an equivalent ASCII character.
D2X Converts a decimal string to a hexadecimal string.
X2B Converts a hexadecimal string to a binary string.
X2C Converts a hexadecimal string to an equivalent ASCII character.
X2D Converts a hexadecimal string to a decimal string.


B2X

Converts a binary string to a hexadecimal string.

Synopsis
hex = B2X(binary)

Args

binary is the original number in binary format.

Returns

The original number in hexadecimal format.

Notes

Binary strings contain only the digits 0 and 1, and are numeric values expressed in base 2. Hexadecimal strings contain the digits 0 to 9, and the letters A to F, inclusive, and are numeric values expressed in base 16.

To increase readability, spaces may be included in a binary string to separate the digits into groups. Each such group must have a multiple of 4 binary digits, except for the first group. If the number of binary digits in the first group is not a multiple of 4, that group is padded at the left with up to three leading zeros, to make it a multiple of four. Spaces can occur only between groups, not as leading or trailing characters. Use STRIP() to remove any leading/trailing spaces.

Each group of four binary digits is translated into a hexadecimal digit in the result string. There will be no extra spaces in the result, and the hexadecimal digits of A to F are in upper case.

The original number is not altered.

Examples

Example use
Return value
B2X('0010 01011100 0011')
'26C3'
B2X('10 0101 11111111')
'26FF'
B2X('0100100 0011')
'243'

See also

X2B


C2D

Converts an ASCII character to an equivalent decimal value.

Synopsis
decimal = C2D(chars, length)

Args

chars is the ASCII character.

If length is specified, it indicates the number of rightmost "bytes" in chars to be converted, and chars is assumed to be in two’s complement format. If length is larger than the actual number of bytes in chars, chars is sign-extended on the left. (ie. chars is padded with either 'FF'x or '00'x bytes on the left-hand side, depending upon whether bit 7 of the leftmost byte is set or clear). If length is too short, only the length rightmost bytes in chars are considered. If length is omitted, then chars is regarded as an unsigned ASCII character.

Returns

The decimal value that is equivalent to the ASCII character.

Notes

This function is very dependent on the character set that your computer is using.

The original ASCII character is not altered.

Examples

Example use
Return value
C2D('a')
97
C2D('09'x) /* Not printable as ASCII, so shown as hex */
9
C2D('FF81'x)
65409
C2D('FF81'x, 2)
-127

See also

D2C


C2X

Converts an ASCII character to an equivalent hexadecimal value.

Synopsis
hex = C2X(chars)

Args

chars is the ASCII character.

Returns

The hexadecimal value that is equivalent to the ASCII character.

Notes

Each ASCII "byte" is translated into a hexadecimal digit in the converted string. There will be no extra spaces in the result, and the hexadecimal digits of A to F are in upper case.

This function is very dependent on the character set that your computer is using.

The original ASCII character is not altered.

Examples

Example use
Return value
C2X('A')
'41'
C2X('JKL')
'6A6B6C'

See also

X2C


D2C

Converts a decimal value to an equivalent ASCII character.

Synopsis
ascii = D2C(decimal, length)

Args

decimal is the decimal value.

length indicates the number of "bytes" desired in the resulting ASCII character. If length is specified, then decimal is assumed to be a signed number (ie, could be negative). The converted ASCII character will be sign-extended on the left to pad out to length. (ie. The result is padded with either 'FF'x or '00'x bytes on the left-hand side, depending upon whether bit 7 of the leftmost byte is set or clear). If length is too short to produce an equivalent ASCII character from decimal, then this raises a SYNTAX error. If length is omitted, then decimal must be an unsigned (ie, positive) number.

Returns

The ASCII character that is equivalent to the decimal value.

Notes

This function is very dependent on the character set that your computer is using.

The original decimal value is not altered.

Examples

Example use
Return value
D2C(0)
'' /* An empty string */
D2C(65)
'A'
D2C(66)
'B'
D2C(-127, 4)
'FFFFFF81'x /* Not printable as ASCII, so shown as hex */

See also

C2D


D2X

Converts a decimal value to a hexadecimal string.

Synopsis
hex = D2X(decimal, length)

Args

decimal is the decimal value.

length indicates the number of "bytes" desired in the resulting hexadecimal string. If length is specified, then decimal is assumed to be a signed number (ie, could be negative). The converted hex string will either be truncated to fit length (if too long), or be sign-extended on the left to pad out to length. (ie. The result is padded with either 'FF'x or '00'x bytes on the left-hand side, depending upon whether bit 7 of the leftmost byte is set or clear). If length is omitted, then decimal must be an unsigned (ie, positive) number.

Returns

The hexadecimal string that is equivalent to the decimal value.

Notes

The original decimal value is not altered.

Examples

Example use
Return value
D2X(9)
9
D2X(48)
30
D2X(129)
81
D2X(129, 1)
1 /* Truncated */
D2X(-127,4)
FF81 /* Sign-extended */

See also

X2D


X2B

Converts a hexadecimal string to a binary string.

Synopsis
binary = X2B(hex)

Args

hex is the original number in hexadecimal format.

Returns

The original number in binary format.

Notes

Binary strings contain only the digits 0 and 1, and are numeric values expressed in base 2. Hexadecimal strings contain the digits 0 to 9, and the letters A to F, inclusive, and are numeric values expressed in base 16.

To increase readability, spaces may be included in a hexadecimal string to separate the digits into groups. Each such group must have a multiple of 2, 4, 8, or 16 binary digits, except for the first group. If the number of binary digits in the first group is not a multiple of 2, that group is padded at the left with a leading zero, to make it a multiple of 2. Spaces can occur only between groups, not as leading or trailing characters. Use STRIP() to remove any leading/trailing spaces.

Each hexadecimal digit is converted to a group of four binary digits in the result string. There will be no extra spaces in the result.

The original number is not altered.

Examples

Example use
Return value
X2B('CF')
'11001111'
X2B('41')
'01000001'
X2B('FF FF')
'1111111111111111'

See also

B2X


X2C

Converts a hexadecimal string to an equivalent ASCII character.

Synopsis
ascii = X2C(hex)

Args

hex is the original number in hexadecimal format.

Returns

The ASCII character that is equivalent to the hexadecimal value.

Notes

The original hexdecimal string is not altered.

Examples

Example use
Return value
X2C('46 6f 6f')
'foo'
X2C('F')
'0F'x /* Not a printable ASCII char, so shown as hex */
X2C('0d')
'0D'x /* Not a printable ASCII char, so shown as hex. This would actually produce a linefeed */

See also

C2X


X2D

Converts a hexadecimal string to a decimal string.

Synopsis
decimal = X2D(hex, length)

Args

hex is the hexadecimal string.

If length is specified, it indicates the number of rightmost digits in hex to be converted, and hex is assumed to be in two’s complement format. If length is larger than the actual number of characters in hex, hex is sign-extended on the left. (ie. hex is padded with either 'F' or '0' characters on the left-hand side, depending upon whether bit 4 of the leftmost digit is set or clear). If length is too short, only the length rightmost digits in hex are considered. If length is omitted, then hex is regarded as an unsigned hexadecimal value.

Returns

The decimal string that is equivalent to the hexadecimal value.

Notes

The original hexadecimal value is not altered.

Examples

Example use
Return value
X2D('1A')
26
X2D('ffff')
65535
X2D('ffff', 5)
65535
X2D('ffff', 4)
-1
X2D('03 24')
792

See also

D2X