Search from Cycling Blog

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: