28
Mar
09

[VB.Net] String To Binary Conversion

    Public Function StringToBinary(ByVal Text As String, Optional ByVal Separator As String = " ") As String
        Dim oReturn As New System.Text.StringBuilder
        For Each Character As Byte In System.Text.ASCIIEncoding.ASCII.GetBytes(Text)
            oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
            oReturn.Append(Separator)
        Next
        Return oReturn.ToString
    End Function

Usage:

Debug.WriteLine(StringToBinary("sim0n")

Would output:
01110011 01101001 01101101 00110000 01101110

Debug.WriteLine(StringToBinary("sim0n", ","))

Would output:
01110011,01101001,01101101,00110000,01101110,

Advertisements

0 Responses to “[VB.Net] String To Binary Conversion”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: