RocketRobotz 

Creator envisioning to create random things.

Forums

Post Reply
Forum Home > Visual Basic Codes *Archive > Text to Binary and vice versa

RocketRobotz
Site Owner
Posts: 8

It's kinda cool but annoying in SOME way LOL

The Button1 or text to binary

        'declares the data

        Dim text As String = Nothing

        'declares the translator

        Dim AP1 As New System.Text.StringBuilder

        'the translation process

        For Each Chars As Byte In System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)

            'converts bytes to 1 & 0

            AP1.Append(Convert.ToString(Chars, 2).PadLeft( 8, "0"))

            'makes a space between letters e.0100001 0101010

            AP1.Append(" ")

        Next

        'finishing touches for the translated text

        text = AP1.ToString.Substring(0, AP1.ToString.Length - 1)

        'shows the data (duh?)

        TextBox2.Text = text

The Button 2 or text to binary

        'declares the data

        Dim text As String = Nothing

        'declares a part of the translator

        Dim CHARS As String = System.Text.RegularExpressions.Regex.Replace(TextBox1.Text, "[^01]", "")

        'declares a part of the translator / converts to a byte

        Dim AP2((CHARS.Length / 8 )- 1) As Byte

        'the translation process

        For index As Integer = 0 To AP2.Length - 1

            AP2(index) = Convert.ToByte(CHARS.Substring(index * 8, 8), 2)

        Next

        'finishing touches

        text = System.Text.ASCIIEncoding.ASCII.GetString(AP2)

        'shows the data (duh?)

        TextBox2.Text = text

----------------------------------------------------------- LOL----------------------------------------------------------------------


--

Creator envisioning stuff. Random stuff.

~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o

Go to the forums here

Go to my Youtube Channel here or Subscribe

~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o~o


August 2, 2011 at 3:38 AM Flag Quote & Reply

You must login to post.