PDA

Click to See Complete Forum and Search --> : text to Ascii and back again.


Crash893
May 17th, 2007, 04:00 PM
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)

jmcilhinney
May 17th, 2007, 06:12 PM
myInt = Convert.ToInt32(myChar);
myChar = Convert.ToChar(myInt);That will convert char objects to their Unicode values and back again.

Crash893
May 17th, 2007, 08:09 PM
myInt = Convert.ToInt32(myChar);
myChar = Convert.ToChar(myInt);That will convert char objects to their Unicode values and back again.

Ill give it a try thanks

Crash893
May 17th, 2007, 08:16 PM
unicode is not a uniform lenght?

jmcilhinney
May 17th, 2007, 08:41 PM
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.

Crash893
May 21st, 2007, 07:34 PM
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?

jmcilhinney
May 21st, 2007, 07:54 PM
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.char character = 'A';
int unicodeValue = Convert.ToInt32(character);
string binaryString = Convert.ToString(unicodeValue, 2).PadLeft(16, '0');

unicodeValue = Convert.ToInt32(binaryString, 2);
character = Convert.ToChar(unicodeValue);

Crash893
May 21st, 2007, 09:24 PM
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.