Hexadecimal To Decimal

This algorithm converts hexadecimal numbers to decimal numbers.



									Public Shared Function HexadecimalToDecimal(hex As String) As Integer
	hex = hex.ToUpper()

	Dim hexLength As Integer = hex.Length
	Dim dec As Double = 0

	For i As Integer = 0 To hexLength - 1
		Dim b As Byte = CByte(AscW(hex(i)))

		If b >= 48 AndAlso b <= 57 Then
			b -= 48
		ElseIf b >= 65 AndAlso b <= 70 Then
			b -= 55
		End If

		dec += b * Math.Pow(16, ((hexLength - i) - 1))
	Next

	Return CInt(Math.Truncate(dec))
End Function
								


Example

									Dim data = "7660F"
Dim value = HexadecimalToDecimal(data)
								


Output

									484879