none
How to convert Octal to Ascii

    Question

  • Hi
    I want to convert Octal value to Ascii
    How can i do that
    Im using vb.net 2008
    Thanks ....
    Tuesday, August 04, 2009 7:06 PM

Answers

  • I looked at the site.  Ok, so they are doing some simple string parsing and applying a conversion.  For instance, MEHDI3, on that site would be entered as:

    %115%105%110%104%111%63
    Ok...  So, a simple version of something to handle this might look like:

    Imports System.Text
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Label1.Text = String.Empty
            Dim letters() As String = TextBox1.Text.Split("%"c)
            Dim buffer As New StringBuilder(letters.Length)
            For Each letter As String In letters
                If Not String.IsNullOrEmpty(letter) Then
                    buffer.Append(ChrW(Convert.ToInt32(letter, 8)))
                End If
            Next
            Label1.Text = buffer.ToString()
        End Sub
    End Class
    

    I mean that is a pretty simple implementation, no error checking or validation of any kind - but, as you can see there is a built in conversion mechanism to/from various bases.



    Tom Shelton
    • Marked as answer by Jeff Shan Monday, August 10, 2009 1:35 AM
    Wednesday, August 05, 2009 2:50 PM

All replies

  • First convert the octal numbers to decimal numbers then get ASCII using the decimal numbers.


    Doug

    SEARCH ... then ask
    Tuesday, August 04, 2009 8:02 PM
  • Option Strict On
    Option Explicit On
    
    Imports System.Text
    
    Module Module1
    
        Sub Main()
            Dim octal() As Byte = {115, 105, 110, 104, 111, 63}
    
            Dim buffer As New StringBuilder(octal.Length)
    
            For Each b As Byte In octal
                buffer.Append(ChrW(Convert.ToInt32(b.ToString(), 8)))
            Next
            Console.WriteLine(buffer)
        End Sub
    
    End Module
    
    HTH

    Tom Shelton
    Tuesday, August 04, 2009 8:10 PM
  • Option Strict On
    
    Option Explicit On
    
    
    
    Imports System.Text
    
    
    
    Module Module1
    
    
    
        Sub Main()
    
            Dim octal() As Byte = {115, 105, 110, 104, 111, 63}
    
    
    
            Dim buffer As New StringBuilder(octal.Length)
    
    
    
            For Each b As Byte In octal
    
                buffer.Append(ChrW(Convert.ToInt32(b.ToString(), 8)))
    
            Next
    
            Console.WriteLine(buffer)
    
        End Sub
    
    
    
    End Module
    
    
    
    
    HTH

    Tom Shelton
    Thanks but it doesn't work

    Tuesday, August 04, 2009 9:04 PM
  • What doesn't work about it?  You never specified how the values were coming in, so I created an array of bytes the specify the octal value of specific ascii chars.

    In fact, the values are the octal string of "MEHDI3".   If that didn't work, then you are going to have to be a bit more specific about why and what your requirements are...



    Tom Shelton
    Tuesday, August 04, 2009 10:17 PM
  • What doesn't work about it?  You never specified how the values were coming in, so I created an array of bytes the specify the octal value of specific ascii chars.

    In fact, the values are the octal string of "MEHDI3".   If that didn't work, then you are going to have to be a bit more specific about why and what your requirements are...



    Tom Shelton

    In fact , Iwant to convert octal to ascii dirctly .
    like this site :  http://www.munc.com/jseffects/asciiConverter.html 
    I have idea but i don't know how can i do it
    The idea:
    convert the string value to byte arr then convert it to octal like your example
    ====================
    but i don't know
    Thanks .......
    Wednesday, August 05, 2009 11:54 AM
  • Don't you know that you already asked the same question before and you abandoned the thread untill moderator marked the thread as answered. You have to revisit the thread because there are a lot of suggestions you can follow to solve the problem. This is the link to your previous thread http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/d230b5f2-cac2-4ed0-8ff4-d63a98117669

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Wednesday, August 05, 2009 12:37 PM
  • I looked at the site.  Ok, so they are doing some simple string parsing and applying a conversion.  For instance, MEHDI3, on that site would be entered as:

    %115%105%110%104%111%63
    Ok...  So, a simple version of something to handle this might look like:

    Imports System.Text
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Label1.Text = String.Empty
            Dim letters() As String = TextBox1.Text.Split("%"c)
            Dim buffer As New StringBuilder(letters.Length)
            For Each letter As String In letters
                If Not String.IsNullOrEmpty(letter) Then
                    buffer.Append(ChrW(Convert.ToInt32(letter, 8)))
                End If
            Next
            Label1.Text = buffer.ToString()
        End Sub
    End Class
    

    I mean that is a pretty simple implementation, no error checking or validation of any kind - but, as you can see there is a built in conversion mechanism to/from various bases.



    Tom Shelton
    • Marked as answer by Jeff Shan Monday, August 10, 2009 1:35 AM
    Wednesday, August 05, 2009 2:50 PM
  • Hi Tom,

    Do you know what is wrong with the Oct function which I sugested in the message thread Kaymaf shows


    http://msdn.microsoft.com/en-us/library/3yyk62cc.aspx

    I know it is not C# but beside that

    :-)



    Cor
    Wednesday, August 05, 2009 4:48 PM
  • Nothing wrong with it exaclty - but, I'm not sure how it applies here.  It is taking a number and converting it into an octal string -  which is exactly the opposite of what's beeing asked.  In this case, it's taking an octal string and converting it to an decimal value.

    Tom Shelton
    Wednesday, August 05, 2009 5:11 PM