Make a Textbox read a binary number. C#

Asked

Viewed 101 times

0

Hello,

I am making a program that simulates a ULA(programmable logic unit), and I need my textbox to read the value written in binary.

For example: In Textbox1 the user would write 1010(decimal number 10).

I need this value to be understood as binary. I can already convert from binary to decimal and vice versa, but what I really need is that the textbox already reads the number that will be placed inside it by the user as binary.

I appreciate the help.

  • You want the textbox to only accept 0 and 1, that’s it?

  • Is Windows Forms, Asp.NET Webforms, Asp.NET MVC, Silverlight, WPF? It’s hard to help without knowing which technology you’re using specifically....

  • It’s windows form application. I want the value read to be binary. If I write 1100 in the textbox, it has to understand 12. I don’t know if you’re giving to understand well what I want! hahaha

  • Put the current textbox code, it’s easier to help.

1 answer

4


The text that is placed in your Textbox can be converted this way:

int val = Convert.ToInt32(textBox.Text, 2);

This class Convert is used for conversion into several numerical bases. In the link there are other examples.

  • Vlw man, I didn’t know about this Convert property. It helped a lot.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.