Hexadecimal To ASCII

This algorithm converts hexadecimal numbers to ASCII code.



									Public Shared Function HexadecimalToASCII(hex As String) As String
	Dim ascii As String = String.Empty

	For i As Integer = 0 To hex.Length - 1 Step 2
		ascii += ChrW(HexadecimalToDecimal(hex.Substring(i, 2)))
	Next

	Return ascii
End Function

Private 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 = "50726F6772616D6D696E6720416C676F726974686D73"
Dim value = HexadecimalToASCII(data)
								


Output

									Programming Algorithms