Search from Cycling Blog

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

  1. btnBinary
  2. txtNum
  3. 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();

}

}

0 comments  

Converting decimal number into Octal number[C#.NET]

Converting decimal number into octal number

Language: C#.NET

Author: Aamir Mustafa

Introduction:

This article will show you how to convert a decimal number into octal number.

How to Use:

Create an empty project

On the form, add a button, two textboxes

  1. btnOctal
  2. txtNum
  3. txtOctal

We will take input through txtNum and show binary number into txtOctal and we will use btnOctal for converting decimal into octal.

Write following code in btnOctal Click event.

Code:

private void btnOctal_Click(object sender, EventArgs e)

{

try

{

long num = 0; //number that we will take through input

num = Convert.ToInt64(txtNum.Text);

txtOctal.Text = Convert.ToString(num, 8); //here 8 means converting to octal

}

catch (Exception ex)

{

MessageBox.Show("Plz enter the number", "Octal", MessageBoxButtons.OK, MessageBoxIcon.Information);

txtNum.Focus();

}

}

0 comments  

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

  1. btnBinary
  2. txtNum
  3. 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();

}

}

0 comments