excelvba large hexadecimal string to decimal code example
Example: excelvba large hexadecimal string to decimal
Function HexToDec(hexStr$)
Dim c&, i&, bitVal
Static hexVals&(), b() As Byte
If (Not Not hexVals) = 0 Then
ReDim hexVals(48 To 102)
For i = 48 To 57
hexVals(i) = c
c = c + 1
Next
For i = 65 To 70
hexVals(i) = c
c = c + 1
Next
c = 10
For i = 97 To 102
hexVals(i) = c
c = c + 1
Next
End If
bitVal = CDec(1)
HexToDec = CDec(0)
b = StrConv(hexStr, vbFromUnicode)
For i = UBound(b) To 0 Step -1
HexToDec = HexToDec + hexVals(b(i)) * bitVal
bitVal = bitVal * 16&
Next
End Function
MsgBox HexToDec("fffffffffffffffffffffff")
MsgBox TypeName(HexToDec("ABCDEF0123456"))