Attribute VB_Name = "modConverter"
Option Explicit


Public Function HexToDec(ByVal szHexValue As String, ByVal bIsBigEndian As Boolean) As String
    Dim szResult As String
    Dim lValue As Long
    Dim lLen As Long
    Dim I As Long
    Dim lCount As Long
    Dim bValues() As Byte
    Dim bIsZero As Boolean
    lLen = Len(szHexValue)
    If (lLen And 1) <> 0 Then
        szHexValue = "0" & szHexValue
        lLen = (lLen + 1)
    End If
    ReDim bValues(0 To (Int(lLen / 2) - 1))
    If bIsBigEndian Then
        lCount = 0
        For I = 1 To lLen Step 2
            bValues(lCount) = Val("&H" & Mid$(szHexValue, I, 2))
            lCount = (lCount + 1)
        Next I
    Else
        lCount = (Int(lLen / 2) - 1)
        For I = 1 To lLen Step 2
            bValues(lCount) = Val("&H" & Mid$(szHexValue, I, 2))
            lCount = (lCount - 1)
        Next I
    End If
    lCount = (UBound(bValues) + 1)
    lValue = 0
    bIsZero = False
    Do While bIsZero = False
        bIsZero = True
        For I = 0 To (lCount - 1)
            If bValues(I) <> 0 Then
                bIsZero = False
            End If
            lValue = (lValue * &H100& + bValues(I))
            bValues(I) = Int(lValue / 100&)
            lValue = (lValue Mod 100&)
        Next I
        If lValue <> 0 And bIsZero = False Then
            szResult = Format$(lValue, "00") & szResult
        End If
        lValue = 0
    Loop
    If Left$(szResult, 1) = "0" Then
        szResult = Mid$(szResult, 2)
    End If
    HexToDec = szResult
End Function
