Introduction
Ascii Binary Converter converts from ASCII Texts to Binary and vice versa.
Image
Important Parts of the Source Code in Visual Basic.NET
Public Function IntegerToBinary(ByVal IntNumber As Integer) As String
Dim Max As Long, Count As Long, ByteCode As Byte
IntegerToBinary = ""
Max = 256
For Count = 1 To 8
ByteCode = 0
Max = Max / 2
If IntNumber >= Max Then
ByteCode = 1
IntNumber = IntNumber - Max
End If
IntegerToBinary = IntegerToBinary & ByteCode
Next Count
End Function
Function BinaryStrToAscii(ByVal StrBinary As String) As String
Dim Length, Count As Integer
Dim StrBinaryBuffer As String = ""
Dim StrReturn As String = ""
Dim BinaryBuffer As String = ""
For Each i In StrBinary
If i = "0" Or i = "1" Then
StrBinaryBuffer &= i
End If
Next
Length = StrBinaryBuffer.Length
Debug.Print("Length: " & Length.ToString)
Count = 0
Do While Count < Length
BinaryBuffer &= StrBinaryBuffer(Count)
If BinaryBuffer.Length = 8 Then
StrReturn &= Chr(BinaryToDecimal(BinaryBuffer))
Debug.Print(BinaryBuffer & " : " & Chr(BinaryToDecimal(BinaryBuffer)))
BinaryBuffer = ""
End If
Count = Count + 1
Loop
Return StrReturn
End Function
Function BinaryToDecimal(ByVal StrBinary As String) As Long
Dim Lenth, a, x As Integer
Lenth = Len(StrBinary) - 1
a = Lenth
Do While Lenth > -1
x = Mid(StrBinary, ((a + 1) - Lenth), 1)
BinaryToDecimal = IIf((x = "1"), BinaryToDecimal + (2 ^ (Lenth)), BinaryToDecimal)
Lenth = Lenth - 1
Loop
End Function