partial void Binary_Changed(UITextField sender)
 {
     if (Binary_TextBox.Text != "" && Binary_TextBox.Text[Binary_TextBox.Text.Length - 1] > '1')
     {
         Binary_TextBox.Text = Binary_TextBox.Text.Substring(0, Binary_TextBox.Text.Length - 1);
     }
     else if (sender.Text.Length == 16 || sender.Text.Length == 32)
     {
         TwoComplament tc = new TwoComplament(BINARY: Binary_TextBox.Text);
         tc.convert();
         Hex_TextBox.Text = tc.hexadecimal;
         if (sender.Text.Length == 16)
         {
             Decimal16_TextBox.Text = tc.dec16;
             tc = new TwoComplament(BINARY: "0000000000000000" + Binary_TextBox.Text);
             tc.convert();
         }
         else
         {
             Decimal16_TextBox.Text = "";
         }
         Decimal32_TextBox.Text = tc.dec32;
     }
     else
     {
         Hex_TextBox.Text       = "";
         Decimal16_TextBox.Text = "";
         Decimal32_TextBox.Text = "";
     }
 }
        partial void Decimal16_Changed(UITextField sender)
        {
            try
            {
                if (Decimal16_TextBox.Text != "" && Decimal16_TextBox.Text != "-" && Convert.ToInt32(Decimal16_TextBox.Text) <= 32767 && Convert.ToInt32(Decimal16_TextBox.Text) >= -32768)
                {
                    TwoComplament tc = new TwoComplament(DECIMAL16: Decimal16_TextBox.Text);
                    tc.convert();

                    Decimal32_TextBox.Text = "";
                    Binary_TextBox.Text    = tc.binary;
                    Hex_TextBox.Text       = tc.hexadecimal;
                }
                else
                {
                    Decimal32_TextBox.Text = "";
                    Binary_TextBox.Text    = "";
                    Hex_TextBox.Text       = "";
                }
            }
            catch
            {
                UIAlertView alert = new UIAlertView()
                {
                    Title   = "Number to Large",
                    Message = "The number being converted is to large"
                };


                alert.AddButton("OK");
                alert.Show();
            }
        }
 partial void Hexadecimal_Changed(UITextField sender)
 {
     if (sender.Text.Length == 4 || sender.Text.Length == 8)
     {
         TwoComplament tc = new TwoComplament(HEXADECIMAL: Hex_TextBox.Text);
         tc.convert();
         Binary_TextBox.Text = tc.binary;
         if (sender.Text.Length == 4)
         {
             Decimal16_TextBox.Text = tc.dec16;
             tc = new TwoComplament(HEXADECIMAL: ("0000" + Hex_TextBox.Text));
             tc.convert();
         }
         else
         {
             Decimal16_TextBox.Text = "";
         }
         Decimal32_TextBox.Text = tc.dec32;
     }
     else
     {
         Binary_TextBox.Text    = "";
         Decimal16_TextBox.Text = "";
         Decimal32_TextBox.Text = "";
     }
 }
Esempio n. 4
0
        private void InputVerifier()
        {
            bool completed = false;

            if (InputTextbox1.Text != "" && Int32.TryParse(InputTextbox1.Text, out input1))
            {
                completed = true;
                TwoComplament convert = new TwoComplament(DECIMAL32: input1.ToString());
                convert.convert();
                Input1Binary.Text = $"({input1}) - {convert.binary}";
            }
            else
            {
                completed         = false;
                Input1Binary.Text = "";
            }
            if (completed && InputTextbox2.Text != "" && Int32.TryParse(InputTextbox2.Text, out input2))
            {
                completed = true;
            }
            else
            {
                completed = false;
                if (SegementedControl.SelectedSegment == 3 && InputTextbox1.Text != "")
                {
                    completed = true;
                }
                Input2Binary.Text = "";
            }

            if (completed)
            {
                int bitwise = Convert.ToInt32(SegementedControl.SelectedSegment);
                int results = 0;
                switch (bitwise)
                {
                case 0:
                    results = AND();
                    TwoComplament convert0 = new TwoComplament(DECIMAL32: input2.ToString());
                    convert0.convert();
                    Input2Binary.Text = $"({input2}) - {convert0.binary}";
                    break;

                case 1:
                    results = OR();
                    TwoComplament convert1 = new TwoComplament(DECIMAL32: input2.ToString());
                    convert1.convert();
                    Input2Binary.Text = $"({input2}) - {convert1.binary}";
                    break;

                case 2:
                    results = XOR();
                    TwoComplament convert2 = new TwoComplament(DECIMAL32: input2.ToString());
                    convert2.convert();
                    Input2Binary.Text = $"({input2}) - {convert2.binary}";
                    break;

                case 3:
                    results = NOT();
                    TwoComplament convert3 = new TwoComplament(DECIMAL32: results.ToString());
                    convert3.convert();
                    Input2Binary.Text = $"({results}) - {convert3.binary}";
                    break;

                case 4:
                    results           = LEFT_SHIFT();
                    Input2Binary.Text = $"LEFT SHIFT BY: {input2}";
                    break;

                case 5:
                    results           = RIGHT_SHIFT();
                    Input2Binary.Text = $"RIGHT SHIFT BY: {input2}";
                    break;
                }
                TwoComplament converts = new TwoComplament(DECIMAL32: results.ToString());
                converts.convert();
                ResultsTextbox.Text = $"({results}) - {converts.binary}";
            }
            else
            {
                ResultsTextbox.Text = "";
            }
        }