View Single Post
  #1 (permalink)  
Old May 7th, 2006, 08:20 PM
skyraider skyraider is offline
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to skyraider
Default Converting an ASCII character to binary?

Hi,

I'm working on a program to encode and decode base64. I know there's a built-in method, but I want to do it myself to really learn something. My question is: how do I take the ASCII value of a letter and convert it to binary? Please see the second-to-last line.

Code:
        Dim UserInput As String = txtInput.Text
        Dim ASCIIinput(txtInput.Text.Length - 1) As Integer

        ' convert user input to ASCII numbers
        Dim i As Integer
        For i = 0 To (UserInput.Length - 1)
            ASCIIinput(i) = AscW(UserInput.Chars(i))
        Next

        ' /* starting encoding process */
        ' take three bytes from the input
        Dim i2 As Integer
        Dim ByteArray(ASCIIinput.Length - 1) As Byte
        For i2 = 0 To (ASCIIinput.Length - 1)
            ByteArray(i2) = CByte(ASCIIinput(i2))
            ' uhh... this just converts it to another 2-digit integer, just like the ASCII number... not an 8-bit binary number
        Next
I'm a total newbie here, but I am working through your VB 2005 book ;) Thanks!

Reply With Quote