How To Make A Binary Converter VB.Net

SOLVED Discussion in 'Web Design & Coding' started by Comptech, Dec 13, 2011.

  1. Comptech

    Comptech ICT Technican

    Joined:
    Dec 11, 2011
    Messages:
    16
    Location:
    UK
    For this project you will need the following;

    2 Labels
    2 Textboxes
    2 Buttons

    Name Label 1 "Convert Binary To Text"
    Name Label 2 "Convert Text To Binary"

    Add Textbox 1 Under Label 1
    Add Textbox 2 Under Label 2

    Name Button 1 "Text To Binary"
    Name Button 2 "Binary To Text"

    Desighn the form how you like

    Code for Binary To Text;

    Dim Val As String = Nothing
    Dim Characters As String = System.Text.RegularExpressions.Regex.Replace(TextBox1.Text, "[^01]", "")
    Dim ByteArray((Characters.Length / 8) - 1) As Byte
    For Index As Integer = 0 To ByteArray.Length - 1
    ByteArray(Index) = Convert.ToByte(Characters.Substring(Index * 8, 8), 2)
    Next
    Val = System.Text.ASCIIEncoding.ASCII.GetString(ByteArray)
    TextBox2.Text = Val




    Code For Text To Binary;

    Dim Val As String = Nothing
    Dim Result As New System.Text.StringBuilder
    For Each Character As Byte In System.Text.ASCIIEncoding.ASCII.GetBytes(TextBox1.Text)
    Result.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
    Result.Append(" ")
    Next
    Val = Result.ToString.Substring(0, Result.ToString.Length - 1)
    TextBox2.Text = Val

    Hope this helps someone or you do the project for fun


    Kind Regards

    Bradley




     
    Comptech, Dec 13, 2011
    #1
    Zeus likes this.
    1. Advertisements

  2. Comptech

    AceInfinity Somewhere...

    Joined:
    Aug 13, 2012
    Messages:
    7
    Location:
    Canada
    I'm not sure what kind of input you have for Binary to Text, I didn't try your Text to Binary, but you've got some implicit conversions going on in your code. Set Option Strict On to see what I mean.

    Here's a quick example of a Text to Binary (String to Base 2) code I put together:
    Code:
    'Text To Binary
    TextBox1.Text = "test"
    Dim input As String = TextBox1.Text
    TextBox2.Text = String.Concat(New UTF8Encoding().GetBytes(input).Select(Function(b) Convert.ToString(b, 2)))
    Here's an example of Binary to Text (Base 2 to String):
    Code:
    'Binary To Text
    TextBox1.Text = "1110100110010111100111110100"
    Dim input As String = TextBox1.Text
    Dim DivideUp As String = String.Concat(Enumerable.Range(0, CInt(input.Length / 7)).Select(Function(i) input.Substring(i * 7, 7) & " ").ToArray).Trim()
    TextBox2.Text = String.Concat(DivideUp.Split(" "c).Select(Function(s) Convert.ToChar(Convert.ToInt32(s, 2))))
     
    AceInfinity, Aug 13, 2012
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. megamuel

    Binary Dreams Logos

    megamuel, Sep 1, 2003, in forum: Media Workshop
    Replies:
    4
    Views:
    2,085
    Nickweb
    May 7, 2004
  2. undeadpenguin

    Binary

    undeadpenguin, Apr 18, 2004, in forum: General Discussion
    Replies:
    8
    Views:
    1,016
  3. Nickweb

    Manual binary competion thread

    Nickweb, Oct 12, 2005, in forum: Web Design & Coding
    Replies:
    15
    Views:
    1,735
    Goober
    Nov 16, 2005
  4. R.P.McMurphy

    Binary Newsgroup ISP

    R.P.McMurphy, Apr 26, 2006, in forum: DIY Computers
    Replies:
    3
    Views:
    496
    Stimey
    Apr 27, 2006
  5. Nick O'Tyme
    Replies:
    0
    Views:
    1,505
    Nick O'Tyme
    Feb 19, 2008
  6. Comptech

    SOLVED How To Make A Desktop Wallpaper Changer VB.Net

    Comptech, Dec 13, 2011, in forum: Web Design & Coding
    Replies:
    0
    Views:
    2,950
    Comptech
    Dec 13, 2011
  7. docsavage20@yahoo.com

    How to make IDE -> SATA converter work

    docsavage20@yahoo.com, Oct 31, 2012, in forum: PC Hardware
    Replies:
    13
    Views:
    5,264
    Flasherly
    Nov 8, 2012
Loading...