Pasar de Hexadecimal a Decimal


La función PasaHexADec, simplemente, devuelve el número en base 10, del número de base 16 que se la pasa por valor.

Attribute VB_Name = "PasarDeHexaADec"

Public Function BMeS(ByVal msb As String) As String
Dim salida
Select Case msb
    Case "A"
        salida = 10
    Case "B"
        salida = 11
    Case "C"
        salida = 12
    Case "E"
        salida = 14
    Case "D"
        salida = 13
    Case "F"
        salida = 15
    Case 0 To 9
        salida = msb
    Case Else
        salida = 0
    End Select

BMeS = salida
End Function

Public Function PasarHexADec(ByVal Vhex As String) As String

'Declara las variables
Dim HE
Dim AA As String
Dim AB As String
Dim AC As String
Dim AD As String
Dim AE As String
Dim AF As String
Dim AG As String
Dim AH As String
Dim BitS As Integer

AA = 0
AB = 0
AC = 0
AD = 0
AE = 0
AF = 0
AG = 0
AH = 0

HE = UCase(Trim(Vhex))
BitS = Len(HE)
AA = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AB = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AC = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AD = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AE = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AF = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AG = Mid(HE, BitS, 1)
BitS = BitS - 1
If BitS = 0 Then GoTo 10
AH = Mid(HE, BitS, 1)

10

AA = BMeS(AA)
AB = BMeS(AB)
AC = BMeS(AC)
AD = BMeS(AD)
AE = BMeS(AE)
AF = BMeS(AF)
AG = BMeS(AG)
AH = BMeS(AH)

PasarHexADec = AA + AB * 16 ^ 1 + AC * 16 ^ 2 + AD * 16 ^ 3 
+ AE * 16 ^ 4 + AF * 16 ^ 5 + AG * 16 ^ 6 + AH * 16 ^ 6

End Function

Se la llama de la siguiente manera:

Dim hexa
Dim Resultado

Resultado = PasaHexADec(hexa)

Donde hexa es cualquier número Hexadecimal menor que un byte y resultado es el número decimal devuelto por la función.

Bajar el proyecto de ejemplo

Autor: Leonardo