user2569803
user2569803

Reputation: 637

Converting string into byte

How do i turn this string into binary without going through the decimal number system first. So I have.

Dim test as string = "11111111"
' And a text field called mask1
mask1.text = Convert.ToByte(m1)
' Then i get an overflow exception everytime

Upvotes: 0

Views: 62

Answers (1)

Andrew Morton
Andrew Morton

Reputation: 25013

You appear to have forgotten to use the number base in the Convert.ToByte method:

Dim s As String = "11111111"
Dim b As Byte = Convert.ToByte(s, 2)
Console.WriteLine(b) ' outputs "255"

Upvotes: 2

Related Questions