DecToHex/ HexToDec



[1]
_dtoh( dec {,iHexD} {,bLowCase} ) DecToHex
  Returns <strS> / <err>
  dec Integer / Float decimal value to be converted to a hex string.
  iHexD The desired string length (max value: 16). If the length of the generated string is less than hexD, it will be prefixed with [iHexD -  string length] zeros.
  bLowCase Boolean. If true, lower case characters will be used in the hex string ( "abcdef" instead of "ABCDEF")
     
  Description Converts a decimal number to a hex string. The string's code page will be the default CP (glbCP).
If the conversion fails, an error will be returned.
     
  Examples put _dtoh(255)
-- FF
put _dtoh(255, 4)
-- 00FF
put _dtoh(255, 4, 1)
-- 00ff

put the maxInteger   , _dtoh(the maxInteger)
-- 2147483647 7FFFFFFF
put the maxInteger+1 , _dtoh(the maxInteger + 1)
-- -2147483648 80000000
put 4 * the maxInteger   , _dtoh(4.0 * the maxInteger) --64bit, aprox. 8GB
-- 8589934588.0000 1FFFFFFFC
     
  Notes This function supports 64bit values.
Negative values are treated as unsigned integer values (see example above)
Since director does not support 64 bit integers, for values larger than -1 (=the maxInteger*2 + 1 = 4GB), a float number should be used as dec.

[2]
_h( hexStr {,iRetType} )  | _htod( hexStr {,iRetType} )  |  strX.htod(  {,iRetType} ) HexToDec
  Returns Integer / Float / <err>
  hexStr String (Director or strX) hex value
  iRetType Integer return type. 0: auto (integer when result <=the maxInteger) , 1: always integer, 2: always float
     
  Description Converts the hexadecimal director string or xStr object to a decimal number.
By default, this command will return an integer for values less than the maxInteger and a float for higher values. Passing an iRetType value forces the Xtra to return the specified type for all values.
     
  Examples put _dtoh(255), _dtoh(255).htod()
-- FF 255
put _htod("FFFF")
-- 65535

hexStr = _s("FFFFFFFF") --or: hexStr = _dtoh( the maxInteger *2.0 + 1)
put hexStr.toDec()
-- 4294967295.0000
put hexStr.toDec(1)     --force the Xtra to return an integer.
-- -1                   --( -1 = the maxInteger * 2 + 1 , as integer)

put _htod("ABCD-WW")           -- pass some invalid data.
-- <xErr 66613 InvalidValue>  --_htod returns an error.
put _h("ABCD-WW")              
-- -1                          --unlike the _htod, _h returns a negative value on error.
 
     
  Notes The decimal value of hexStrings larger than 8 digits is an 64bit value,
Forcing the Xtra to return integer type for such values, the result value will be: decVal mod 0xFFFFFFFF