viernes, 5 de octubre de 2012

convertir de octal a decimal


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
         
            string numero = textBox1.Text;
            int y = numero.Length;
            int Octal = int.Parse(numero);
            double sumador = 0;
            int x=y;
            for (int i = 0; i < y; i++)
            {
             
                int ultimo_numero = Octal % 10;
                Octal = Octal / 10;
                if (ultimo_numero == 9)
                {
                    i = y + 1;
                    MessageBox.Show("numero no es octal");
                 
                }
                else
                {
                    sumador = sumador + (Math.Pow(8, i) * ultimo_numero);

                }
                 x = i;
           
            }
            if (x==y-1)
                textBox2.Text = sumador.ToString();
            else
                textBox2.Text = "intenta de nuevo";

        }
    }
}

//por paulo andres escobar

2 comentarios:

  1. Quisiera saber como convertir de Octal a Decimal y viceversa en NetBeans

    ResponderEliminar
  2. y en AIDE en android alguien sabe como se reaiza??

    ResponderEliminar