udfDecToHex (2)
str udfDecToHex (int)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDecToHex (intDecimal, intPadLength)
hdlBB = BinaryAlloc (4)
BinaryPoke4 (hdlBB, 0, intDecimal)
strHex = BinaryPeekHex (hdlBB, 3, 1) : BinaryPeekHex (hdlBB, 2, 1) : BinaryPeekHex (hdlBB, 1, 1) : BinaryPeekHex (hdlBB, 0, 1)
hdlBB = BinaryFree (hdlBB)
If intPadLength >= 8 Then Return strHex
strHex = StrReplace (StrReplace (StrTrim (StrReplace (strHex : @LF, "0", " ")), " ", "0"), @LF, "")
IntZ = StrLen (strHex)
Return StrFixLeft (strHex, "0", Min (8, Max (intZ, intPadLength)))
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

If Param0 Then If Param1 == ".." Then Return ; Leave this script here when called by another script with the specified parameter.


; Test.

intNum = +25
strHex = udfDecToHex (intNum, 0) ; "19"
Message (intNum, strHex)

intNum = -25
strHex = udfDecToHex (intNum, 0) ; "FFFFFFE7"
Message (intNum, strHex)

intNum = 4078
strHex = udfDecToHex (intNum, 4) ; "0FEE"
Message (intNum, strHex)

Exit