excel vba big hex string to decimal string

'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

'
'
'

0
0
Awgiedawgie 440220 points

                                    'Extremely fast function to parse hexidecimal digits from text string:

Function ForceStringToHexDigitsOnly$(s$)
    Dim i&amp;, p&amp;, max&amp;, t&amp;
    Dim b() As Byte, res() As Byte
    Static keep() As Boolean

    Const VALS$ = &quot;0123456789 ABCDEFabcdef&quot;
    
    If (Not Not keep) = 0 Then
        ReDim keep(0 To 255)
        For i = 1 To Len(VALS)
            keep(Asc(Mid$(VALS, i, 1))) = 1
        Next
    End If
    
    max = Len(s)
    ReDim res(0 To max)
    b = StrConv(s, vbFromUnicode)
    For i = 0 To Len(s) - 1
        t = b(i)
        If keep(t) Then
            res(p) = t
            p = p + 1
        End If
    Next
    ForceStringToHexDigitsOnly = Left$(StrConv(res, vbUnicode), p)
End Function

'------------------------------------------------------------------------------

MsgBox ForceStringToHexDigitsOnly(&quot;qA01mzBoo7o2F%F&quot;)  '&lt;--displays: A01B72FF

'
'
'

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
excel vba convert string to hex excel hex to decimal convert macro excel vba big decimal to hex excel vba big hex to dec unsigned excel vba big hex to dec xl vba Convert HEX string to Unsigned INT vba Convert HEX string to Unsigned INT excelvba Convert HEX string to Unsigned INT excel vba Convert HEX string to Unsigned INT excel vba hex to dec vba hex to decimal excel vba hex to decimal excel vba hex string to decimal excel vba hexstring to decimal excel vba hexidecimal string to decimal integer excel vba hexidecimal string to decimal vba hexidecimal string to decimal vba large hexidecimal string to decimal excel xl vba large hexidecimal string to decimal excel vba large hexidecimal string to decimal vba large hexidecimal string to decimal xl vba large hexadecimal string to decimal excelvba large hexadecimal string to decimal excel vba large hexadecimal string to decimal vba large hexadecimal string to decimal vba large hex string to decimal excel xl vba large hex string to decimal excel vba large hex string to decimal vba large hex string to decimal vba big hex string to decimal excelvba big hex string to decimal excel vba big hex string to decimal excel vba big hex string to decimal string excel vba keep only hexadecimal digits excel vba keep only hexadecimal digits in string parse filter excel vba keep only hex digits in string parse filter excel vba keep only hex digits in string parse excelvba keep only hex digits from text string excel vba keep only hex digits from text string excel vba filter hex digits from string vba filter hex digits from string excel vba filter hex digits from string xl vba parse hex digits string filter excel vba parse hex digits string filter vba parse hex digits string filter vba parse hex digits text string filter excelvba parse hex digits text string filter excel vba parse hex digits text string filter vba parse hex digits text string excel vba parse hex digits string excel xl vba parse hex digits string excelvba parse hex digits string excel vba parse hex digits string vba parse hex digits string vba parse hex digits from string excelvba parse hex digits from string excel vba parse hex digits from string
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source