ASCII To Hexadecimal

This algorithm converts ASCII code to hexadecimal numbers.



									Public Shared Function ASCIIToHexadecimal(str As String) As String
	Dim hex As String = String.Empty

	For i As Integer = 0 To str.Length - 1
		Dim chex As String = DecimalToHexadecimal(AscW(str(i)))

		If chex.Length = 1 Then
			chex = chex.Insert(0, "0")
		End If

		hex += chex
	Next

	Return hex
End Function

Private Shared Function DecimalToHexadecimal(dec As Integer) As String
	If dec < 1 Then Return "0"

	Dim hex As Integer = dec
	Dim hexStr As String = String.Empty

	While dec > 0
		hex = dec Mod 16

		If hex < 10 Then
			hexStr = hexStr.Insert(0, Convert.ToChar(hex + 48).ToString())
		Else
			hexStr = hexStr.Insert(0, Convert.ToChar(hex + 55).ToString())
		End If

		dec = Int(dec / 16)
	End While

	Return hexStr
End Function
								


Example

									Dim data = "Programming Algorithms"
Dim value = ASCIIToHexadecimal(data)
								


Output

									50726F6772616D6D696E6720416C676F726974686D73