Another way:
|
A |
B |
C |
1 |
45317471814165458 |
A10000219A23D2 |
B1:=sCur2Hex(A1) |
Option Explicit
Type uCur
c As Currency
End Type
Type uai8
ai(0 To 7) As Byte
End Type
Function sCur2Hex(sInp As String) As String
' shg 2016
Dim uC As uCur
Dim uai As uai8
Dim sCur As String
sCur = Replace(sInp, ".", "")
sCur = Left(sCur, Len(sCur) - 4) & "." & Right(sCur, 4)
sCur = Replace(LTrim(Replace(sCur, "0", " ")), " ", "0")
If Len(sCur) > 20 Then GoTo NFG
If Len(sCur) = 20 And sCur > "922337203685477.5807" Then GoTo NFG
uC.c = CCur(sCur)
LSet uai = uC
ArrRev uai.ai
sCur2Hex = Byte2Hex(uai.ai)
sCur2Hex = Replace(LTrim(Replace(sCur2Hex, "0", " ")), " ", "0")
Exit Function
NFG:
sCur2Hex = "Too big!"
End Function
Function ArrRev(ByRef av As Variant)
' shg 2008
Dim i As Long
Dim j As Long
Dim vTmp As Variant
i = LBound(av)
j = UBound(av)
Do While i < j
vTmp = av(i)
av(i) = av(j)
av(j) = vTmp
i = i + 1
j = j - 1
Loop
End Function
Function Byte2Hex(ai() As Byte, Optional sSep As String = "") As String
' Converts ai to a hex string
' VBA only
Dim i As Long
For i = LBound(ai) To UBound(ai)
Byte2Hex = Byte2Hex & Right("0" & Hex(ai(i)), 2) & sSep
Next i
Byte2Hex = Left(Byte2Hex, Len(Byte2Hex) - Len(sSep))
End Function
Bookmarks