public char[] ReturnSum() { char[] sum = { BinaryLogic.TrueOrFalse(Add3.Ci), BinaryLogic.TrueOrFalse(Add3.Si), BinaryLogic.TrueOrFalse(Add2.Si), BinaryLogic.TrueOrFalse(Add1.Si), BinaryLogic.TrueOrFalse(Add0.Si) }; return(sum); }
public void CalculateOutputs() { try { var binNumber0 = BinaryLogic.IntToBin(Number0); var binNumber1 = BinaryLogic.IntToBin(Number1); Add0.SetValues(BinaryLogic.TrueOrFalse(binNumber0[3]), BinaryLogic.TrueOrFalse(binNumber1[3]), false); Add1.SetValues(BinaryLogic.TrueOrFalse(binNumber0[2]), BinaryLogic.TrueOrFalse(binNumber1[2]), Add0.Ci); Add2.SetValues(BinaryLogic.TrueOrFalse(binNumber0[1]), BinaryLogic.TrueOrFalse(binNumber1[1]), Add1.Ci); Add3.SetValues(BinaryLogic.TrueOrFalse(binNumber0[0]), BinaryLogic.TrueOrFalse(binNumber1[0]), Add2.Ci); } catch (Exception e) { MessageBox.Show(e.Message); } }
public void Calculate() { try { if (Convert.ToInt32(BoxNumber0.Text) > 15 || Convert.ToInt32(BoxNumber0.Text) < 0 || Convert.ToInt32(BoxNumber1.Text) > 15 || Convert.ToInt32(BoxNumber1.Text) < 0) { MessageBox.Show("Numbers out of range. Numbers have to be:" + Environment.NewLine + " 1. Less than 15" + Environment.NewLine + " 2. More than 0"); throw new Exception(); } _adder.SetValues(Convert.ToInt32(BoxNumber0.Text), Convert.ToInt32(BoxNumber1.Text)); BoxBinNumber0.Text = new string(BinaryLogic.IntToBin(Convert.ToInt32(BoxNumber0.Text))); BoxBinNumber1.Text = new string(BinaryLogic.IntToBin(Convert.ToInt32(BoxNumber1.Text))); BoxOutputBin.Text = new string(_adder.ReturnSum()); BoxOutputDec.Text = Convert.ToInt32(BoxOutputBin.Text, 2).ToString(); SetColours(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }