I'm developing a calculator, it will give all of the functionality of calc.exe; however it will have a few of my own adjustments that I use constantly and have to do on paper or with different methods on calc.

I need help with subtraction, multiplication, and division the most.

I'm using custom enums, arrays, methods, and other ways of customizing my source making it easier to manage.

public enum NumericFormat
{
	Binary,
	Octal,
	Decimal,
	Hexadecimal
}

public enum Precision
{
	_64Bit,
	_32Bit,
	_16Bit,
	_8Bit
}

private int[] Input = new int[100];
private string[] Operators = new string[99];

private int Index = 0;

private int Current = 0;
private int Results = 0;

private string HexadecimalResults = "";
private string OctalResults = "";
private string BinaryResults = "";

private NumericFormat CurrentFormat = NumericFormat.Decimal;
private NumericFormat PreviousFormat = NumericFormat.Decimal;

private Precision CurrentPrecision = Precision._64Bit;

private bool OperatorClicked = false;

Those are my main variables, accessed throughout the source code. My main problem with subtraction is that it's backwards. If I subtract 3 from 15 it returns -12.

My problem with multiplication and division is that it's just returning the final value in my array.

// Source for adding, subtracting, multiplying, and dividing.
private void Equals_Click(object sender, EventArgs e)
{
	for (int i = 0; i < Index; i++)
	{
		if (Operators[i] == "+")
			Results += Input[i];

		else if (Operators[i] == "-")
			Results -= Input[i];

		else if (Operators[i] == "*")
			Results *= Input[i];

		else if (Operators[i] == "/")
			Results /= Input[i];
	}

	if (Current != 0)
	{
		if (Operators[Index] == "+")
			Results += Current;

		else if (Operators[Index] == "-")
			Results -= Current;

		else if (Operators[Index] == "*")
			Results *= Current;

		else if (Operators[Index] == "/")
			Results /= Current;
	}

	// The following two lines have not been tested, but are replacing a for loop that goes through and resets all elements in these arrays to 0 and empty.
	Operators = new string[99];
	Input = new int[100];

	Index = 0;

	ConvertFormat();
	UpdateOutput();
}

private void UpdateOutput()
{
	InputDisplay1.Text = "0";
	InputDisplay2.Text = Results.ToString();
}

private void Add_Click(object sender, EventArgs e)
{
	ConvertToDecimal(InputDisplay1.Text, CurrentFormat);
	Input[Index] = Current;
	Operators[Index] = "+";
	
	Index++;
	
	OperatorClicked = true;
}

private void Subtract_Click(object sender, EventArgs e)
{
	ConvertToDecimal(InputDisplay1.Text, CurrentFormat);
	Input[Index] = Current;
	Operators[Index] = "-";
	
	Index++;
	
	OperatorClicked = true;
}

private void Multiply_Click(object sender, EventArgs e)
{
	ConvertToDecimal(InputDisplay1.Text, CurrentFormat);
	Input[Index] = Current;
	Operators[Index] = "*";
	
	Index++;
	
	OperatorClicked = true;
}

private void Divide_Click(object sender, EventArgs e)
{
	ConvertToDecimal(InputDisplay1.Text, CurrentFormat);
	Input[Index] = Current;
	Operators[Index] = "/";
	
	Index++;
	
	OperatorClicked = true;
}

My other problem is with scientific notation, I've developed a method that only sort of works, so I will research more and fix that, however I'm trying to figure out how to convert double values to hex, binary, and octal and then outputing them in scientific notation. For example with hex:

12D687 in notation should be c.something * a^5;

However it constantly outputs zero. I event tried converting the number to decimal first, performing the division or multiplication by 10, and then converting it back. Any help with these topics is greatly appreciated. I don't have my entire source code available so I can't give the other methods I use in my calc but those are the basics. I believe the logic error should be located in the Equals_Click method. All the ConvertToDecimal method does is convert the input value to decimal in order to store it for arithmatic. Then I am outputing it converted back to the currently selected format.

Recommended Answers

All 5 Replies

I would not use thz decimal typz here, decimal is for doing money calculations.
Use the double type instead.

I'm not using the Decimal variable type. I'm converting the numbers to the Decimal number system.

This is the entire source code. As I stated originally I have developed an application extension for use with many of my applications and this happens to be using it. I included the namespaces and classes that it uses in my original post. Any help is appreciated.

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;

using Dev9;
using Dev9.Conversions;
using Dev9.MathAlgebraPhysics;

namespace AGI_Calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // -----------------------------------------
        // ********Binary Conversion Table**********
        // -----------------------------------------
        // |0000 0000 0000 0000 0000 0000 0000 0000|
        // |63                  47               32|
        // |                                       |
        // |0000 0000 0000 0000 0000 0000 0000 0000|
        // |31                  15                0|
        // |                                       |
        // -----------------------------------------


        // Name 		    - Var 	:: Max Size
        // QuadWord 		- Int64 :: 9,223,372,036,854,775,807
        // DoubleWord 		- Int32 :: 2,147,483,647
        // Word 		    - Int16 :: 32,767
        // Byte 		    - Int8 	:: 127


        // Needed for conversions between numeric formats.
        private Numerics Numerics = new Numerics();
        private Notations Notations = new Notations();

        private enum NumericFormat
        {
            Binary,
            Octal,
            Decimal,
            Hexadecimal
        }

        private enum Precision
        {
            QWord,
            DWord,
            Word,
            Byte
        }

        private int InputIndex = 0;

        private long[] Input64 = new Int64[100];

        private string[] InputHex = new string[100];
        private string[] InputOctal = new string[100];
        private string[] InputBinary = new string[100];

        private string[] Operators = new string[99];

        private long Results64 = 0;
        private long Current64 = 0;

        private string CurrentHex = "";
        private string CurrentOctal = "";
        private string CurrentBinary = "";

        private NumericFormat CurrentFormat = NumericFormat.Decimal;
        private Dev9.Conversions.NumericFormat CurrentDev9 = Dev9.Conversions.NumericFormat.Decimal;
        private Dev9.Conversions.NumericFormat LastFormat = Dev9.Conversions.NumericFormat.Decimal;

        private Precision CurrentPrecision = Precision.QWord;

        private bool OperatorClicked = false;

        private void Form1_Load(object sender, EventArgs e)
        {
            StoreLasts.Start();
        }

        private void UpdateInput2()
        {
            InputDisplay2.Text = "";

            for (int i = 0; i < InputIndex; i++)
            {
                if (CurrentFormat == NumericFormat.Decimal)
                    InputDisplay2.Text += Input64[i].ToString() + " " + Operators[i] + " ";

                if (CurrentFormat == NumericFormat.Binary)
                    InputDisplay2.Text += Numerics.ToBinary(Input64[i]) + " " + Operators[i] + " ";

                if (CurrentFormat == NumericFormat.Octal)
                    InputDisplay2.Text += Numerics.ToOctal(Input64[i]) + " " + Operators[i] + " ";

                if (CurrentFormat == NumericFormat.Hexadecimal)
                    InputDisplay2.Text += Numerics.ToHex(Input64[i]) + " " + Operators[i] + " ";
            }

            InputDisplay1.Text = Current64.ToString();
        }

        private void DetermineAndOutputPrecision()
        {
            if (CurrentFormat == NumericFormat.Decimal)
            {
                Current64 = Convert.ToInt64(InputDisplay1.Text);
                InputDisplay1.Text = Current64.ToString();
            }

            if (CurrentPrecision == Precision.QWord)
                DetermineMax64(Current64);

            if (CurrentPrecision == Precision.DWord)
                DetermineMax32(Current64);

            if (CurrentPrecision == Precision.Word)
                DetermineMax16(Current64);

            if (CurrentPrecision == Precision.Byte)
                DetermineMax8(Current64);
        }

        private void ConvertValues()
        {
            if (CurrentFormat == NumericFormat.Decimal)
            {
                int h = Numerics.ToDecimal(InputDisplay1.Text, LastFormat);
                InputDisplay1.Text = h.ToString();
                DetermineAndOutputPrecision();
            }

            else if (CurrentFormat == NumericFormat.Hexadecimal)
            {
                int h = Numerics.ToDecimal(InputDisplay1.Text, LastFormat);
                CurrentHex = Numerics.ToHex(h);

                InputDisplay1.Text = CurrentHex;
            }

            else if (CurrentFormat == NumericFormat.Octal)
            {
                int h = Numerics.ToDecimal(InputDisplay1.Text, LastFormat);
                CurrentOctal = Numerics.ToOctal(h);

                InputDisplay1.Text = CurrentOctal;
            }

            else if (CurrentFormat == NumericFormat.Binary)
            {
                int h = Numerics.ToDecimal(InputDisplay1.Text, LastFormat);
                CurrentBinary = Numerics.ToBinary(h);

                InputDisplay1.Text = CurrentBinary;
            }
        }

        private void DetermineMax64(long Number)
        {
            try
            {
                if (CurrentFormat == NumericFormat.Decimal)
                Current64 = Convert.ToInt64(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal));

                else if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Convert.ToInt64(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary));

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Convert.ToInt64(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal));

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Convert.ToInt64(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal));
            }

            catch (Exception e)
            {
                MessageBox.Show("The number: " + Number.ToString() + " was too large for a Qword, please use Scientific Notation to calculate your values.");
            }
        }

        private void DetermineMax32(long Number)
        {
            try
            {
                if (CurrentFormat == NumericFormat.Decimal)
                    Current64 = Convert.ToInt32(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal));

                else if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Convert.ToInt32(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary));

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Convert.ToInt32(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal));

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Convert.ToInt32(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal));
            }

            catch (Exception e)
            {
                MessageBox.Show("The number: " + Number.ToString() + " was too large for a Qword, please use Scientific Notation to calculate your values.");
            }
        }

        private void DetermineMax16(long Number)
        {
            try
            {
                if (CurrentFormat == NumericFormat.Decimal)
                    Current64 = Convert.ToInt16(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal));

                else if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Convert.ToInt16(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary));

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Convert.ToInt16(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal));

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Convert.ToInt16(Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal));
            }

            catch (Exception e)
            {
                MessageBox.Show("The number: " + Number.ToString() + " was too large for a Qword, please use Scientific Notation to calculate your values.");
            }
        }

        private void DetermineMax8(long Number)
        {
            if (CurrentFormat == NumericFormat.Decimal)
                Number = Numerics.ToDecimal(Number.ToString(), Dev9.Conversions.NumericFormat.Decimal);

            else if (CurrentFormat == NumericFormat.Binary)
                Number = Numerics.ToDecimal(Number.ToString(), Dev9.Conversions.NumericFormat.Binary);

            else if (CurrentFormat == NumericFormat.Octal)
                Number = Numerics.ToDecimal(Number.ToString(), Dev9.Conversions.NumericFormat.Octal);

            else if (CurrentFormat == NumericFormat.Hexadecimal)
                Number = Numerics.ToDecimal(Number.ToString(), Dev9.Conversions.NumericFormat.Hexadecimal);

            if (Number > 127)
            {
                Current64 = 0;
                MessageBox.Show("The number: " + Number.ToString() + " was too large for a Byte, please use Word.");
            }
        }

        #region Numerics
        private void Number0_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "0";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "0";

            DetermineAndOutputPrecision();
        }

        private void Number1_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "1";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "1";

            DetermineAndOutputPrecision();
        }

        private void Number2_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "2";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "2";

            DetermineAndOutputPrecision();
        }

        private void Number3_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "3";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "3";

            DetermineAndOutputPrecision();
        }

        private void Number4_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "4";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "4";

            DetermineAndOutputPrecision();
        }

        private void Number5_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "5";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "5";

            DetermineAndOutputPrecision();
        }

        private void Number6_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "6";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "6";

            DetermineAndOutputPrecision();
        }

        private void Number7_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "7";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "7";

            DetermineAndOutputPrecision();
        }

        private void Number8_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "8";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "8";

            DetermineAndOutputPrecision();
        }

        private void Number9_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "9";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "9";

            DetermineAndOutputPrecision();
        }

        private void NumberA_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "a";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "a";

            DetermineAndOutputPrecision();
        }

        private void NumberB_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "b";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "b";

            DetermineAndOutputPrecision();
        }

        private void NumberC_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "c";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "c";

            DetermineAndOutputPrecision();
        }

        private void NumberD_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "d";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "d";

            DetermineAndOutputPrecision();
        }

        private void NumberE_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "e";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "e";

            DetermineAndOutputPrecision();
        }

        private void NumberF_Click(object sender, EventArgs e)
        {
            if (InputDisplay1.Text == "0" || OperatorClicked)
            {
                InputDisplay1.Text = "f";
                OperatorClicked = false;
            }

            else
                InputDisplay1.Text += "f";

            DetermineAndOutputPrecision();
        }
        #endregion

        private void Add_Click(object sender, EventArgs e)
        {
            OperatorClicked = true;

            if (CurrentPrecision == Precision.QWord)
            {
                if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary);

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal);

                else if (CurrentFormat == NumericFormat.Decimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal);

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal);

                Input64[InputIndex] = Current64;
                Operators[InputIndex] = "+";
                Current64 = 0;
            }

            InputIndex++;

            UpdateInput2();
        }

        private void Subtract_Click(object sender, EventArgs e)
        {
            OperatorClicked = true;

            if (CurrentPrecision == Precision.QWord)
            {
                if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary);

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal);

                else if (CurrentFormat == NumericFormat.Decimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal);

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal);

                Input64[InputIndex] = Current64;
                Operators[InputIndex] = "-";
                Current64 = 0;
            }

            InputIndex++;

            UpdateInput2();
        }

        private void Multiply_Click(object sender, EventArgs e)
        {
            OperatorClicked = true;

            if (CurrentPrecision == Precision.QWord)
            {
                if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary);

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal);

                else if (CurrentFormat == NumericFormat.Decimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal);

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal);

                Input64[InputIndex] = Current64;
                Operators[InputIndex] = "*";
                Current64 = 0;
            }

            InputIndex++;

            UpdateInput2();
        }

        private void Divide_Click(object sender, EventArgs e)
        {
            OperatorClicked = true;

            if (CurrentPrecision == Precision.QWord)
            {
                if (CurrentFormat == NumericFormat.Binary)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Binary);

                else if (CurrentFormat == NumericFormat.Octal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Octal);

                else if (CurrentFormat == NumericFormat.Decimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Decimal);

                else if (CurrentFormat == NumericFormat.Hexadecimal)
                    Current64 = Numerics.ToDecimal(InputDisplay1.Text, Dev9.Conversions.NumericFormat.Hexadecimal);

                Input64[InputIndex] = Current64;
                Operators[InputIndex] = "/";
                Current64 = 0;
            }

            InputIndex++;

            UpdateInput2();
        }

        private void Scientific_Click(object sender, EventArgs e)
        {
            if (CurrentFormat == NumericFormat.Decimal)
                InputDisplay1.Text = Notations.Scientific(Convert.ToDouble(Numerics.ToDecimal(InputDisplay1.Text, CurrentDev9)), CurrentDev9);

            if (CurrentFormat == NumericFormat.Hexadecimal)
                InputDisplay1.Text = Notations.Scientific(Convert.ToDouble(Numerics.ToDecimal(InputDisplay1.Text, CurrentDev9)), CurrentDev9);
        }

        private void Equals_Click(object sender, EventArgs e)
        {
            ChangeToDecimal(sender, e);
            Results64 = 0;

            Current64 = Convert.ToInt64(InputDisplay1.Text);

            for (int i = 0; i < InputIndex; i++)
            {
                if (Operators[i] == "+")
                {
                    if (InputIndex == 0)
                        Results64 = Input64[i];

                    else
                        Results64 += Input64[i];
                }

                else if (Operators[i] == "-")
                {
                    if (InputIndex == 0)
                        Results64 = Input64[i];

                    else
                        Results64 -= Input64[i];
                }

                else if (Operators[i] == "*")
                {
                    if (InputIndex == 0)
                        Results64 = Input64[i];

                    else
                        Results64 *= Input64[i];
                }

                else if (Operators[i] == "/")
                {
                    if (InputIndex == 0)
                        Results64 = Input64[i];

                    else
                        Results64 /= Input64[i];
                }
            }

            if (Operators[InputIndex] == "+")
                Results64 += Current64;

            else if (Operators[InputIndex] == "-")
                Results64 -= Current64;

            else if (Operators[InputIndex] == "*")
                Results64 *= Current64;

            else if (Operators[InputIndex] == "/")
                Results64 /= Current64;

            InputDisplay1.Text = Results64.ToString();
            InputDisplay2.Text = "";

            for (int i = 0; i < InputIndex; i++)
            {
                Operators[i] = "";
                Input64[i] = 0;
            }

            InputIndex = 0;
        }

        private void True_Click(object sender, EventArgs e)
        {

        }

        private void False_Click(object sender, EventArgs e)
        {

        }

        private void And_Click(object sender, EventArgs e)
        {

        }

        private void Or_Click(object sender, EventArgs e)
        {

        }

        private void Not_Click(object sender, EventArgs e)
        {

        }

        private void Mod_Click(object sender, EventArgs e)
        {

        }

        private void LeftParen_Click(object sender, EventArgs e)
        {

        }

        private void RightParen_Click(object sender, EventArgs e)
        {

        }

        private void XToTheSecond_Click(object sender, EventArgs e)
        {

        }

        private void XToY_Click(object sender, EventArgs e)
        {

        }

        private void ChangeToHex(object sender, EventArgs e)
        {
            CurrentFormat = NumericFormat.Hexadecimal;
            CurrentDev9 = Dev9.Conversions.NumericFormat.Hexadecimal;

            if (!Number2.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Binary;

            else if (!Number8.Enabled && Number2.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Octal;

            else if (!NumberA.Enabled && Number8.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Decimal;

            Number2.Enabled = true;
            Number3.Enabled = true;
            Number4.Enabled = true;
            Number5.Enabled = true;
            Number6.Enabled = true;
            Number7.Enabled = true;
            Number8.Enabled = true;
            Number9.Enabled = true;
            NumberA.Enabled = true;
            NumberB.Enabled = true;
            NumberC.Enabled = true;
            NumberD.Enabled = true;
            NumberE.Enabled = true;
            NumberF.Enabled = true;

            ConvertValues();
        }

        private void ChangeToDecimal(object sender, EventArgs e)
        {
            CurrentFormat = NumericFormat.Decimal;
            CurrentDev9 = Dev9.Conversions.NumericFormat.Decimal;

            if (!Number2.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Binary;

            else if (!Number8.Enabled && Number2.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Octal;

            else if (NumberA.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Hexadecimal;

            Number2.Enabled = true;
            Number3.Enabled = true;
            Number4.Enabled = true;
            Number5.Enabled = true;
            Number6.Enabled = true;
            Number7.Enabled = true;
            Number8.Enabled = true;
            Number9.Enabled = true;
            NumberA.Enabled = false;
            NumberB.Enabled = false;
            NumberC.Enabled = false;
            NumberD.Enabled = false;
            NumberE.Enabled = false;
            NumberF.Enabled = false;

            ConvertValues();
        }

        private void ChangeToOctal(object sender, EventArgs e)
        {
            CurrentFormat = NumericFormat.Octal;
            CurrentDev9 = Dev9.Conversions.NumericFormat.Octal;

            if (!Number2.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Binary;

            else if (!NumberA.Enabled && Number8.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Decimal;

            else if (NumberA.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Hexadecimal;

            Number2.Enabled = true;
            Number3.Enabled = true;
            Number4.Enabled = true;
            Number5.Enabled = true;
            Number6.Enabled = true;
            Number7.Enabled = true;
            Number8.Enabled = false;
            Number9.Enabled = false;
            NumberA.Enabled = false;
            NumberB.Enabled = false;
            NumberC.Enabled = false;
            NumberD.Enabled = false;
            NumberE.Enabled = false;
            NumberF.Enabled = false;

            ConvertValues();
        }

        private void ChangeToBinary(object sender, EventArgs e)
        {
            CurrentFormat = NumericFormat.Binary;
            CurrentDev9 = Dev9.Conversions.NumericFormat.Binary;

            if (!Number8.Enabled && Number2.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Octal;

            else if (!NumberA.Enabled && Number8.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Decimal;

            else if (NumberA.Enabled)
                LastFormat = Dev9.Conversions.NumericFormat.Hexadecimal;

            Number2.Enabled = false;
            Number3.Enabled = false;
            Number4.Enabled = false;
            Number5.Enabled = false;
            Number6.Enabled = false;
            Number7.Enabled = false;
            Number8.Enabled = false;
            Number9.Enabled = false;
            NumberA.Enabled = false;
            NumberB.Enabled = false;
            NumberC.Enabled = false;
            NumberD.Enabled = false;
            NumberE.Enabled = false;
            NumberF.Enabled = false;

            ConvertValues();
        }

        private void ChangeToQword(object sender, EventArgs e)
        {
            CurrentPrecision = Precision.QWord;
        }

        private void ChangeToDword(object sender, EventArgs e)
        {
            CurrentPrecision = Precision.DWord;
        }

        private void ChangeToWord(object sender, EventArgs e)
        {
            CurrentPrecision = Precision.Word;
        }

        private void ChangeToByte(object sender, EventArgs e)
        {
            CurrentPrecision = Precision.Byte;
        }

        private void UpdateBinaryGrid(object sender, EventArgs e)
        {
            string Binary = ConvertToBinary();
            int X = 63;

            while (Binary.Length < 64)
            {
                Binary += "0";
            }

            string[] Forths = new string[16];

            for (int i = 0; i < 16; i++)
            {
                Forths[i] = "0000";
            }

            for (int i = 0; i < 4; i++)
            {
                Forths[i] = Binary.Substring(X, 1) + Binary.Substring(X - 1, 1) + Binary.Substring(X - 2, 1) + Binary.Substring(X - 3, 1);
                X -= 4;
            }

            Binary1.Text = Forths[0];
            Binary2.Text = Forths[1];
            Binary3.Text = Forths[2];
            Binary4.Text = Forths[3];
            Binary5.Text = Forths[4];
            Binary6.Text = Forths[5];
            Binary7.Text = Forths[6];
            Binary8.Text = Forths[7];
            Binary9.Text = Forths[8];
            Binary10.Text = Forths[9];
            Binary11.Text = Forths[10];
            Binary12.Text = Forths[11];
            Binary13.Text = Forths[12];
            Binary14.Text = Forths[13];
            Binary15.Text = Forths[14];
            Binary16.Text = Forths[15];
        }

        private string ConvertToBinary()
        {
            string x = "";

            if (CurrentFormat == NumericFormat.Binary)
                x = CurrentBinary;

            else if (CurrentFormat == NumericFormat.Octal)
            {
                long i = Numerics.ToDecimal(CurrentOctal, Dev9.Conversions.NumericFormat.Octal);
                x = Numerics.ToBinary(i);
            }

            else if (CurrentFormat == NumericFormat.Decimal)
                x = Numerics.ToBinary(Current64);

            else if (CurrentFormat == NumericFormat.Hexadecimal)
            {
                long i = Numerics.ToDecimal(CurrentHex, Dev9.Conversions.NumericFormat.Hexadecimal);
                x = Numerics.ToBinary(i);
            }

            return x;
        }

        private void Clear_Click(object sender, EventArgs e)
        {
            Results64 = 0;

            InputDisplay1.Text = Results64.ToString();
            InputDisplay2.Text = "";

            for (int i = 0; i < InputIndex; i++)
            {
                Operators[i] = "";
                Input64[i] = 0;
            }

            InputIndex = 0;
        }
    }
}

There are many methods inside of my source that are still under development. I'm wanting help with scientific notation, subtracting, multiplying, and dividing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.