Converting decimal to binary[C#.NET]
Converting decimal number into Binary number
Language: C#.NET
Author: Aamir Mustafa
Introduction:
This article will show you how to convert a decimal number into binary number.
How to Use:
Create an empty project
On the form, add a button, two textboxes
- btnBinary
- txtNum
- txtBinary
We will take input through txtNum and show binary number into txtBinary and we will use btnBinary for converting decimal into Binary.
Write following code in btnBinary Click event.
[Code]
private void btnBinary_Click(object sender, EventArgs e)
{
try
{
long num = 0; //number that we will take through input
num = System.Convert.ToInt64(txtNum.Text);
txtBinary.Text = Convert.ToString(num, 2); //here 2 means converting to binary
}
catch (Exception ex)
{
MessageBox.Show("Plz enter the number", "Binary", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtNum.Focus();
}
}