Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[New\Source\Release] Binary Code <> English Converter [New\Source\Release]
#16
Here's my version:

[Image: Ukngi.png]

Full Codes:
Code:
Imports System.Text
Imports System.Text.RegularExpressions

Public Class Form1

    'String to Binary
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        RichTextBox2.Text = TextToBinary(RichTextBox1.Text)
    End Sub

    'Binary to string
    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        RichTextBox1.Text = BinaryToText(RichTextBox2.Text)
    End Sub

    'Clear string to binary RichTextBox
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        RichTextBox1.Clear()
    End Sub

    ''Clear binary to string RichTextBox
    Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
        RichTextBox2.Clear()
    End Sub

    'Clipboard string to binary RichTextBox
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        If RichTextBox1.SelectedText <> "" Then
            Clipboard.SetDataObject(RichTextBox1.SelectedText)
        End If
    End Sub

    'Clipboard binary to string RichTextBox
    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        If RichTextBox2.SelectedText <> "" Then
            Clipboard.SetDataObject(RichTextBox2.SelectedText)
        End If
    End Sub

    'Only allow 0 and 1 in binary to string RichTextBox
    Private Sub RichTextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox2.KeyPress
        If e.KeyChar < "0" Or e.KeyChar > "1" Then
            MessageBox.Show("Only binary digits allowed.")
            e.Handled = True
        Else
            RichTextBox1.Text = BinaryToText(RichTextBox2.Text)
        End If
    End Sub

    ' Conversion to Binary
    Private Shared Function TextToBinary(ByVal Text As String, Optional ByVal Separator As String = " ") As String
        Try
            Dim oReturn As New StringBuilder
            ' Convert to ASCII and go through all the bytes
            For Each Character As Byte In ASCIIEncoding.ASCII.GetBytes(Text)
                oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
                oReturn.Append(Separator)
            Next
            Return oReturn.ToString
        Catch ex As Exception
            Return ex.Message
        End Try
    End Function

    'Conversion to Text
    Private Shared Function BinaryToText(ByVal BinaryText As String) As String
        Try
            Dim Characters As String = Regex.Replace(BinaryText, "[^01]", "")
            Dim ByteArray((Characters.Length / 8) - 1) As Byte
            ' Retrieve the original byte array
            For Index As Integer = 0 To ByteArray.Length - 1
                ByteArray(Index) = Convert.ToByte(Characters.Substring(Index * 8, 8), 2)
            Next
            ' Convert the ASCII-array to a Unicode string
            Return ASCIIEncoding.ASCII.GetString(ByteArray)
        Catch ex As Exception
            Return ex.Message
        End Try
    End Function
End Class

The cleaner, the better.
USB Anti-virus? Try USB Drive Defender
[Image: 8bQCusS.jpg]
Reply


Messages In This Thread
RE: [New\Source\Release] Binary Code <> English Converter [New\Source\Release] - by euverve - 05-15-2011, 04:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] Guidtech [Better then HWID][WITH VB FILES!] The-One 5 7,113 08-07-2015, 06:18 AM
Last Post: darknessxk
  [Source] Proxy Grabber [Cool] Hell Guardian 12 9,311 04-07-2015, 11:46 AM
Last Post: polas
  [SOURCE] Advanced Webcam Viewer TalishHF 4 3,902 08-25-2014, 01:20 AM
Last Post: dark_move
  [Source] Deep Freeze Pass Reader for 7.10.020.3176 euverve 6 6,519 01-02-2014, 09:07 PM
Last Post: idrcelab
  [Release] Password Enhancer v1.0 [/Release] Resistance 11 5,923 09-29-2013, 08:58 PM
Last Post: Resistance

Forum Jump:


Users browsing this thread: 17 Guest(s)