CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: ASCII to Base32

  1. #1
    Join Date
    Aug 2015
    Posts
    2

    ASCII to Base32

    I have a arduino project that I am working on. I need the 10 characters changed from ASCII to Hex and Base32. I have the Hex working but I can not figure out how to convert to the Base32. Here is my code. I have been all overGoogle and I cannot find any clear answer. Any help or a point in the right direction would be great.

    Code:
        Private Sub Clear_Click(sender As Object, e As EventArgs) Handles Clear.Click
            txtbox.Text = ""
            arduino.Text = ""
            Auth.Text = ""
        End Sub
    
        Private Sub Ok_Click(sender As Object, e As EventArgs) Handles Ok.Click
    
            arduino.Text = "{" & String.Join(", ", txtbox.Text.Select(Function(c) String.Format("0x{0:X2}", Convert.ToInt32(c)))) & "}"
    
        End Sub
    
    End Class

  2. #2
    Join Date
    Aug 2015
    Posts
    2

    Re: ASCII to Base32

    I have updated my code to below but now I am getting this error.

    Value of type 'String' cannot be converted to 'Byte()'. WindowsApplication2

    Code:
            Private Sub Ok_Click(sender As Object, e As EventArgs) Handles Ok.Click
    
            arduino.Text = "{" & String.Join(", ", txtbox.Text.Select(Function(c) String.Format("0x{0:X2}", Convert.ToInt32(c)))) & "}"
    
            Dim DataToEncode As Byte() = txtbox.Text
    
            Dim Base32 As String
            Base32 = DataToEncode.ToBase32String()
            Auth.Text = Base32
        End Sub

  3. #3
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,345

    Re: ASCII to Base32

    Yes you can not place a string in a byte, nor can you assign a string directly to a byte array. You can turn a string into a byte array which is what you would need to do there.

    Have a look at the GetBytes method of the Encoding class

    Example
    Code:
    sBytes = Encoding.Default.GetBytes(DataString)
    Last edited by DataMiser; August 22nd, 2015 at 05:08 PM.
    Always use [code][/code] tags when posting code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)