excelvba large hexadecimal string to decimal
'VBA function to convert a hexadecimal string into a decimal. Uses
'the Decimal Variant subtype to allow for much larger values than the
'worksheet function HEX2DEC() or CLng("&h" & HexVal) can achieve. It
'returns an UNSIGNED Decimal integer...
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") '<--displays: 4951760157141521099596496895
MsgBox TypeName(HexToDec("ABCDEF0123456")) '<--displays: Decimal
'
'
'
Are there any code examples left?
New code examples in category VBA
-
VBA 2022-03-27 20:55:02 excel vba check if all substrings in list are in string
-
VBA 2022-03-27 20:40:39 excel vba set cell value to empty
-
VBA 2022-03-27 17:05:52 vba simple quote
-
VBA 2022-03-27 14:30:19 textbox find and replace vb
-
VBA 2022-03-27 09:10:21 nested if else in vb.net
-
VBA 2022-03-27 09:10:09 excel vba string to bits
-
VBA 2022-03-25 02:00:15 vba verticalalignment
-
VBA 2022-03-24 12:20:06 Excel web scraping
-
VBA 2022-03-24 10:11:00 excel vba BitToLong
-
VBA 2022-03-21 18:00:05 excel vba save file txt