Hello.
I hope that the following routines, written by Doug Hennig, would help you:
Decimal2Hex:
------------------------------
*==============================================================================
* Function: Decimal2Hex
* Purpose: Convert a decimal number to a hex string
* Author: Doug Hennig
* Copyright: (c) 2000 Stonefield Systems Group Inc.
* Last Revision: 11/02/2000
* Parameters: tnValue - the decimal value
* tnPlaces - the number of places needed (optional: if it
* isn't specified, 4 is used)
* Returns: the hex string
* Environment in: none
* Environment out: none
*==============================================================================
lparameters tnValue, ;
tnPlaces
local lnPlaces, ;
lcHex, ;
lnDecimal, ;
lnCurrDecimals, ;
lnPlaces, ;
lnI, ;
lnExponent, ;
lnTemp, ;
lcOut
lnPlaces = iif(pcount() = 1, 4, tnPlaces)
lcHex = ''
lnDecimal = tnValue
lnCurrDecimals = set('DECIMALS')
lnPlaces = iif(pcount() = 1, 4, tnPlaces)
set decimals to 17
for lnI = lnPlaces to 1 step -1
lnExponent = 256 ^ (lnI - 1)
lnTemp = int(lnDecimal/lnExponent)
lcHex = lcHex + chr(lnTemp)
lnDecimal = lnDecimal - lnTemp * lnExponent
next lnI
set decimals to lnCurrDecimals
* Reverse the order of the characters.
lcOut = ''
for lnI = 1 to lnPlaces
lcOut = lcOut + substr(lcHex, lnPlaces - lnI + 1, 1)
next lnI
return lcOut
-----------------------
and Hex2Decimal
-----------------------
*==============================================================================
* Function: Hex2Decimal
* Purpose: Converts a value in Intel format to a decimal value
* Author: Doug Hennig
* Copyright: (c) 2000 Stonefield Systems Group Inc.
* Last Revision: 11/02/2000
* Parameters: tcValue - the value to convert
* tlSigned - .T. if the value is signed
* Returns: the numeric value
* Environment in: none
* Environment out: none
*==============================================================================
lparameters tcValue, ;
tlSigned
local lnDecimal, ;
lnLen, ;
lnI, ;
lnMSB, ;
lnMax
lnDecimal = 0
lnLen = len(tcValue)
for lnI = 1 to lnLen
lnDecimal = lnDecimal + asc(substr(tcValue, lnI, 1)) * 256 ^ (lnI - 1)
next lnI
if tlSigned
lnMSB = (lnLen * 8) - 1
if bittest(lnDecimal, lnMSB)
lnMax = 2 ^ (lnMSB + 1)
lnDecimal = lnResult - lnMax
endif bittest(lnDecimal, lnMSB)
endif tlSigned
return lnDecimal
------------------
Hope this helps. Grigore Dolghin
Class Software
Bucharest, Romania