Caché MultiValue Basic Reference
DTX
[Home] [Back] [Next]
InterSystems: The power behind what matters   
Class Reference   
Search:    

Converts a number from decimal to hexadecimal.
Synopsis
DTX(decnum[,width])
Arguments
decnum An expression that resolves to an integer.
width Optional — An expression that resolves to a positive integer. width specifies the number of digits of the returned value, for the purpose of zero-padding.
Description
The DTX function returns a decimal integer converted to hexadecimal. The decnum value can be a positive or negative integer. If decnum is a positive integer, DTX returns the number of hexadecimal digits needed to express it. If decnum is a negative integer, DTX returns high values. For example, DTX(-1) returns FFFFFFFFFFFFFFFF. If you specify decnum as a fractional number, DTX generates a <FUNCTION> error.
The optional width argument pads the return value with leading zeros. If width is equal to or smaller than the number of hexadecimal digits in the return value, width is ignored. If width is larger than the needed number of hexadecimal digits, DTX pads the returned hexadecimal number with leading zeros. With a negative decnum, if width is larger than 16, it pads the returned hexadecimal number with leading zeros. If you specify width as a fractional number, DTX truncates it to the integer portion. If you specify width as a negative number, width is ignored.
If decnum is zero, the null string, or a non-numeric string, DTX returns 0; width padding is applied. If decnum is a mixed numeric string, the numeric part is parsed until a non-numeric character is encountered. Thus “7dwarves” is parsed as 7.
Use XTD to convert from hexadecimal to decimal.
Examples
The following examples return positive integers converted to hexadecimal:
PRINT DTX(12);        ! Returns "C"
PRINT DTX(12,4);      ! Returns "000C"
PRINT DTX(199);       ! Returns "C7"
PRINT DTX(199,1);     ! Returns "C7"
The following examples return negative integers converted to hexadecimal:
PRINT DTX(-199);        ! Returns "FFFFFFFFFFFFFF39"
PRINT DTX(-199,4);      ! Returns "FFFFFFFFFFFFFF39"
PRINT DTX(-199,17);     ! Returns "0FFFFFFFFFFFFFF39"
The following examples all return zero. Zero padding is provided, if specified:
PRINT DTX(0);       ! Returns "0"
PRINT DTX(-0);      ! Returns "0"
PRINT DTX(0,4);     ! Returns "0000"
PRINT DTX("",4);    ! Returns "0000"
PRINT DTX("foo",4); ! Returns "0000"
See Also