I've been trying to figure this out for hours now, and I've given up on trying to solve it myself. Basically what I need to do, is convert a "double octet" binary string, such as "11010011 01011101", into a byte or char type if possible.
I use the following code to convert my Unicode text into binary:
And that seems to work perfectly, I get the results I'm after. But how do I then convert those results back into a string? So far, the only code that has worked for me is this:Code:Private Function ByteToStr(ByVal bt() As Byte) As String Dim st As New StringBuilder For Each byt As Byte In bt st.Append(Convert.ToString(byt, 2).PadLeft(8, "0"c) & " ") Next Return st.ToString End Function Private Function TxtToBin(ByVal Str As String) As String Return ByteToStr(Encoding.Unicode.GetBytes(Str.ToCharArray)) End Function
But that gives me weird results. The "Convert.FromBase64String" obviously isn't what I'm after. Any help would be great. If I can convert the "binary string" into a bytes or chars I can get it into a string.Code:Private Function BinToStr(ByVal BinStr As String) Dim str() As String = BinStr.Split(" "c) Dim bt As New List(Of Byte) For Each s As String In str For Each d As Byte In Convert.FromBase64String(s) bt.Add(d) Next Next Return Encoding.Unicode.GetString(bt.ToArray) End Function
EDIT: I suppose I'm dealing with the hexadecimal base, 16 bits? I really don't know much about base numbers or encoding...




Reply With Quote
