This should be a simple one,
I need to convert a string into a binary string. Then I need to take that binary string, and convert it back to a regular ascii string.
Anyone know how?
Printable View
This should be a simple one,
I need to convert a string into a binary string. Then I need to take that binary string, and convert it back to a regular ascii string.
Anyone know how?
VB Code:
'string to binary 'second argument converts the string from a base 10 number 'other valid arguments are 2, 8 & 16 'Method converts to a 32 bit Signed integer. Dim i as Int i = System.Convert.ToInt32 ("12345", 10) 'binary to string Dim s as String s = i.ToString()
Other valid conversions
ToInt16 - converts to a 16 bit signed integer
ToInt64 - converts to a 64 bit signed integer
ToUInt16 - converts to a 16 bit unsigned integer
ToUInt32 - converts to a 32 bit unsigned integer
ToUInt64 - converts to a 64 bit unsigned integer
Thanks, but I don't think that will work.
I have a string, lets say:
"Hello, how are you."
I want to convert that to binary equivalent.
This may help you out ! http://www.developer.be/index.cfm/fu...0functions.htm
I don't quite understand. That is binary (ascii characters=bytes=8bits per byte).Quote:
Originally posted by hellswraith
Thanks, but I don't think that will work.
I have a string, lets say:
"Hello, how are you."
I want to convert that to binary equivalent.
Here's how you convert a string to a byte array (if that is indeed what you're asking):
This should also work with Unicode strings because a unicode character is nothing more than 2 asciii characters (if not, there are many more Encoding classes in the Text namespace that should do what you need, and you use them the same way).Code:Dim strHello As String = "Hello there, how are you?"
Dim btHello() As Byte
btHello = System.Text.ASCIIEncoding.ASCII.GetBytes(strHello)
I hope I didn't misunderstand your question.
Ok, this will make it easier to understand, I want to do something like this:
http://nickciske.com/tools/binary.php
I don't think there is a built in function for that. Maybe you could make a for-loop that counts in binary by either adding 1 to an integer or multiplying it by 10. Don't ask me for this algorithm though.Quote:
Originally posted by hellswraith
Ok, this will make it easier to understand, I want to do something like this:
http://nickciske.com/tools/binary.php
EDIT:
Just wanted to say that a recursive function might be easier to use for this than a for-loop, but I don't know
hmm it should be easy to find some code for this. I think what you have to do is to convert each character of the string to ascii code, then you should convert the ascii code to binary.
To convert a number to binary you basically keep dividing the number by 2 and you save the remainder. I dunno how to explain it. IE:
91 is your number
91\2 = 45 and it's remainder is 1 (91 mod 2 =1)
now you look at 45:
45\2=22 and 45 mod 2 =1
now do the same with 22:
22\2=11 and 22 mod 2 =0
11\2=5 and 11 mod 2 =1
5\2=2 and 5 mod 2=1
2\2=1 and 2 mod 2=0
1\2 is less than 0, STOP
now you write down all the red numbers in REVERSE: 1011011. That's 91 in binary :) for the last part, I wrote the "1\2" in red. I think you always consider the last number to be 1. Just remember that when you convert an ascii to binary, it has to be 8 digits. So if you get something like 1101 you have to put 4 zeros next to it to make it 8 digits:00001101.
I hope I'm not making a mistake here:D this was my 7th grade memory:D:D:D:D
I got it working, but it wasn't as pretty as I would have liked. You can check it out here.
http://www.variantx.com/Main/DeveloperTools.aspx
Hellswraith...I checked out your resume...and noticed some spelling errors (a pet peeve of mine)...just thought I would let you know...I don't think employers like to see spelling errors from educated individuals...especially when you can use a spell checker.
under RELEVANT EXPERIENCE
2nd sentence
*proceedures should be procedures
2nd paragraph 1st sentence
*files is printed twice
Hmm , it worked fine for me . Did you get any sort of errors ?:rolleyes:Quote:
Originally posted by hellswraith
I got it working, but it wasn't as pretty as I would have liked. You can check it out here.
http://www.variantx.com/Main/DeveloperTools.aspx
I dont know how you accomplished that, but I use this:Quote:
I got it working, but it wasn't as pretty as I would have liked. You can check it out here.
VB Code:
Dim mytext() As Char = "This is a test" Dim c As Char, s,bs As String, i as Integer For Each c In mytext s += Integer.Parse(Convert.ToString(Asc(c), 2)).ToString("00000000") Next MessageBox.Show("Converted to binary: " & s) 'Edits: Forgot to include binary to string: here is the code: For i = 0 To s1.Length - 1 Step 8 bs += Chr((Convert.ToByte(s.Substring(i, 8), 2))) Next MessageBox.Show("Converted back to String: " & bs)
Thanks, you scared me, I thought I was sending those mistakes out on my 'real' resume when applying for jobs. I went straight for the word document and found there was no error in there. That was relief. Thanks for the heads up on the web based one, I have changed those.Quote:
Originally posted by Memnoch1207
Hellswraith...I checked out your resume...and noticed some spelling errors (a pet peeve of mine)...just thought I would let you know...I don't think employers like to see spelling errors from educated individuals...especially when you can use a spell checker.
under RELEVANT EXPERIENCE
2nd sentence
*proceedures should be procedures
2nd paragraph 1st sentence
*files is printed twice