PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Binary String into Byte
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Binary String into Byte
![]() |
Binary String into Byte |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hello,
I have a string containing a binary code, mystring = "1010100" and i want to write this string ino a byte, not an byte array to interpretate it as an ASCII Letter. I found a way to put it in a byte array, but then i have a bytearray containing (49), (48) ,(49), (48) ,... Thank you very much for your help Tobias |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Here is one way you can do it.
Private Function ToByte(ByVal s As String) As Byte Dim b As Byte = 0 Dim digit As Byte = 2 ^ (s.Length - 1) For Each c As Char In s If c = "1"c Then b = b Or digit End If digit = digit / 2 Next Return b End Function ==================== Clay Burch Syncfusion, Inc. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
> I have a string containing a binary code,
> > mystring = "1010100" > > and i want to write this string ino a byte, not an byte array to > interpretate it as an ASCII Letter. I thought Mudhead had answered this perfectly in his post to your identical thread that you started yesterday: \\\ Dim b As Byte b = Convert.ToByte("1010100", 2) /// Was there something wrong with that solution? -- (O)enone |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

