示例#1
0
        private void btnBinToDec_Click(object sender, EventArgs e)
        {
            int flag = 0;

            // VALIDACION EN EL TEXTO PARA BINARIO
            if (textBox1.Text.Length != 0)
            {
                for (int i = textBox1.Text.Length; i > 0; i--)
                {
                    if (!(textBox1.Text[i - 1].Equals('0') || textBox1.Text[i - 1].Equals('1')))
                    {
                        flag = 1;
                        break;
                    }
                }
            }
            else
            {
                flag = 1;
            }
            // MENSAJE DE ERROR
            if (flag == 1)
            {
                MessageBox.Show("Ingrese un número Binario!", "Error Detectado", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // SI TODO ESTA OK CREAMOS EL OBJETO Y EMPEZAMOS LA CONVERSIÖN
                NumeroBinario nroBinario = new NumeroBinario(textBox1.Text);
                txtResultadoDec.Text = ((double)nroBinario).ToString();
            }
        }
 /// <summary>
 /// On press button, tryes to convert a binary to a decimal number, then shows it in the txtResultadoDec.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnBinToDec_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrWhiteSpace(txtBinario.Text))
     {
         NumeroBinario binaryNumber = (NumeroBinario)txtBinario.Text;
         txtResultadoDec.Text = ((NumeroDecimal)binaryNumber).GetDecimalNumber().ToString();
     }
     else
     {
         MessageBox.Show("Error while trying to convert the Binary to Decimal.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }