p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Visual Basic 2005 Basics (http://p2p.wrox.com/forumdisplay.php?f=137)
-   -   Converting an ASCII character to binary? (http://p2p.wrox.com/showthread.php?t=42238)

skyraider May 7th, 2006 08:20 PM

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!



All times are GMT -4. The time now is 10:23 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.