Converting decimal to binary[VC++.NET]
Converting decimal number into Binary number
Language: Visual C++.NET
Author: Aamir Mustafa
Introduction:
This article will show you how to convert a decimal number into binary number.
How to Convert:
This is Visual C++.Net so here is some different technique to create a project. I will use here Windows Form Application Project.
Follow these steps to create a project
File->New->New Project
Another window will open,in this window select CLR and then choose
Windows Form Application.
After that enter a name for your project and click OK
A new project will be created and a new form will be front of you.
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.
Double click on btnBinary
Write following code in btnBinary Click event.
[Code]
private: System::Void btnBinary_Click(System::Object^ sender, System::EventArgs^ e)
{
try
{
long num=0;
num=Convert::ToInt64(txtNum->Text);
txtBinary->Text=Convert::ToString(num,2);
}
catch(Exception ^ex)
{
MessageBox::Show("Please enter the number","Binary",MessageBoxButtons::OK,MessageBoxIcon::Information);
txtNum->Focus();
}
}