Results 1 to 8 of 8

Thread: text to Ascii and back again.

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    text to Ascii and back again.

    Hi all,

    Im working on a project and i need to conver text to a numeric value and back again so i figured i would use Ascii


    what i hope to do is something like this webpage
    http://getyourwebsitehere.com/jswb/text_to_ascii.html


    I hope to convert something like "test"

    to &# 116; &# 101;& # 120; &# 116;

    text and then remove the &#

    (added spaces so it will display)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: text to Ascii and back again.

    C# Code:
    1. myInt = Convert.ToInt32(myChar);
    2. myChar = Convert.ToChar(myInt);
    That will convert char objects to their Unicode values and back again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: text to Ascii and back again.

    Quote Originally Posted by jmcilhinney
    C# Code:
    1. myInt = Convert.ToInt32(myChar);
    2. myChar = Convert.ToChar(myInt);
    That will convert char objects to their Unicode values and back again.
    Ill give it a try thanks

  4. #4

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: text to Ascii and back again.

    unicode is not a uniform lenght?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: text to Ascii and back again.

    Unicode uses two bytes per character, while ASCII only use one byte. ASCII was inadequate because one byte can only have 256 values. Unicode can have 65536 different characters while ASCII can have only 256. Unicode uses the same numeric value as ASCII for most ASCII characters, but there is a block where they do not coincide. Those are less-used characters though. All the letters numbers and common punctuation characters have the values in ASCII and Unicode.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: text to Ascii and back again.

    I am trying to keep the number down to the smallest possible.

    is there anyway to get the value of the bytes in binary to a string

    like 1=0001 2=0010 for ascii?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: text to Ascii and back again.

    I'm not 100% sure what you mean. Convert.ToInt32 returns an Integer value. If you want to convert that, or any, integer to a binary string you use the Convert.ToString method, e.g.
    c# Code:
    1. char character = 'A';
    2. int unicodeValue = Convert.ToInt32(character);
    3. string binaryString = Convert.ToString(unicodeValue, 2).PadLeft(16, '0');
    4.  
    5. unicodeValue = Convert.ToInt32(binaryString, 2);
    6. character = Convert.ToChar(unicodeValue);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: text to Ascii and back again.

    I'm trying to take a string and create a numeric value that i can encrypt

    then later decrypt it and turn it back into a string

    obviously the smaller the numeric value the easier it will be for me.

Posting Permissions

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



Click Here to Expand Forum to Full Width