Function DecToHexchars24(inDec As Long) As String
'Copywrite (c) 2004 Randy Gamage
'This function converts a decimal value into a string
'of hex characters, in 24-bit signed notation
'least significant byte first (little-endian)
'Example
'DecToHexchars24(520) => chr(8) & chr(2) & chr(0)
'DecToHexchars24(-2) => chr(FE) & chr(FF) & chr(FF)

'If negative, convert to two's complement:
If inDec < 0 Then inDec = 2 ^ 24 + inDec

Dim strTemp As String
Dim i As Integer
strTemp = ""

For i = 1 To 3
  strTemp = strTemp & Chr(inDec Mod 256)
  inDec = inDec \ 256
Next i

DecToHexchars24 = strTemp
End Function

Function DecToHexchars16(inDec As Long) As String
'This function converts a decimal value into a string
'of hex characters, in 16-bit signed notation,
'least significant byte first (little-endian)
'Example
'DecToHexchars16(520) => chr(8) & chr(2)
'DecToHexchars16(-2) => chr(FE) & chr(FF)

'If negative, convert to two's complement:
If inDec < 0 Then inDec = 2 ^ 16 + inDec

Dim strTemp As String
Dim i As Integer
strTemp = ""

For i = 1 To 2
  strTemp = strTemp & Chr(inDec Mod 256)
  inDec = inDec \ 256
Next i

DecToHexchars16 = strTemp
End Function

Function DecToHexchars8(inDec As Long) As String
'This function converts a decimal value into a string
'of hex characters, in 8-bit signed notation,
'least significant byte first (little-endian)
'Example
'DecToHexchars8(127) => chr(127)
'DecToHexchars8(-2) => chr(FE)

'If negative, convert to two's complement:
If inDec < 0 Then inDec = 2 ^ 8 + inDec

Dim strTemp As String
Dim i As Integer
strTemp = ""

strTemp = strTemp & Chr(inDec Mod 256)
inDec = inDec \ 256
'If inDec > 256, then only the modulo will be considered
DecToHexchars8 = strTemp
End Function