ASCII To Binary

This algorithm converts ASCII code to binary numbers.



									Public Shared Function ASCIIToBinary(ByVal str As String) As String
	Dim bin As String = String.Empty

	For i As Integer = 0 To str.Length - 1
		Dim cBin As String = DecimalToBinary(Convert.ToInt32(str(i)))

		If cBin.Length < 8 Then
			cBin = cBin.PadLeft(8, "0"c)
		End If

		bin += cBin
	Next

	Return bin
End Function

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

	Dim binStr As String = String.Empty

	While dec > 0
		binStr = binStr.Insert(0, (dec Mod 2).ToString())

		dec = Int(dec / 2)
	End While

	Return binStr
End Function
								


Example

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


Output

									01010000011100100110111101100111011100100110000101101101011011010110100101101110011001110010000001000001011011000110011101101111011100100110100101110100011010000110110101110011