0

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
2
  • What is m1? Did you mean to pass the string test into Convert.ToByte? Commented Feb 11, 2014 at 20:43
  • I think the string is a representation of a Byte number in binary number format and he wants to convert this into an actual number (in this case 256). @user: your code tries to assign the number 11111111 (11 million) to a byte variable that goes from 0 to 255, that's what causes the exception at least. Commented Feb 11, 2014 at 20:46

1 Answer 1

2

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.