Beispiel #1
0
        private BitArray StrongDivision() //13
        {
            var result = FirstOperand.ToInt() / SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Beispiel #2
0
        private BitArray ReadInBase() //18
        {
            var bs      = SecondOperand.ToInt();
            var operand = GetStringFromDialog();

            if (bs > 36 || bs < 0)
            {
                return(BitArrayExtension.GetBitArray(0, 9));
            }
            try
            {
                operand = operand.ToUpper();

                int result = 0;
                for (int i = operand.Length - 1, mul = 0; i >= 0; i--, mul++)
                {
                    result += (int)Math.Pow(bs, mul) * (Char.IsDigit(operand[i]) ?
                                                        (int)Char.GetNumericValue(operand[i]) :
                                                        (operand[i] - 55));
                }
                FirstOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            }
            catch (Exception)
            {
                return(BitArrayExtension.GetBitArray(0, 9));
            }
            return(FirstOperand);
        }
Beispiel #3
0
        private BitArray Modulo() //14
        {
            var result = FirstOperand.ToInt() % SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Beispiel #4
0
        private BitArray Multiplication() //12
        {
            var result = FirstOperand.ToInt() * SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Beispiel #5
0
        private BitArray Subtraction() //11
        {
            var result = FirstOperand.ToInt() - SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
Beispiel #6
0
        private BitArray Addition() //10
        {
            var result = FirstOperand.ToInt() + SecondOperand.ToInt();

            ThirdOperand = BitArrayExtension.GetBitArray(result, OperandLenght);
            return(ThirdOperand);
        }
        private IEnumerable <Command> ReadFromBinaryFile(string path)
        {
            var commandList = new List <Command>();

            try
            {
                using (var reader = new BinaryReader(File.Open(path, FileMode.Open)))
                {
                    var id = 1;
                    while (reader.PeekChar() > -1)
                    {
                        var num         = reader.ReadInt32();
                        var newBitArray = BitArrayExtension.GetBitArray(num, OperandLenght * 3 + OperationLenght);
                        var newCommand  = new Command(newBitArray, id++);
                        newCommand.PropertyChanged += Command_PropertyChanged;
                        commandList.Add(newCommand);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(commandList);
        }
Beispiel #8
0
 public Command(int id = 0)
 {
     ThirdOperand    = BitArrayExtension.GetBitArray(0, OperandLenght);
     SecondOperand   = BitArrayExtension.GetBitArray(0, OperandLenght);
     FirstOperand    = BitArrayExtension.GetBitArray(0, OperandLenght);
     Operation       = BitArrayExtension.GetBitArray(0, OperationLenght);
     CommandId       = id;
     IsCurrent       = false;
     IsBreakpointSet = false;
     Operations      = InitializeOperations();
 }
Beispiel #9
0
        private BitArray GetNumInSecOperandBase() //17
        {
            var num = FirstOperand.ToInt();
            var bs  = SecondOperand.ToInt();

            if (bs > 36 || bs < 0)
            {
                ShowMessage("Incorrect Base");
                return(BitArrayExtension.GetBitArray(0, 9));
            }

            ShowMessage(ConvertToBase(num, bs));
            return(BitArrayExtension.GetBitArray(num, 1));
        }
Beispiel #10
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var bitArr = value as String;
            int len    = System.Convert.ToInt32(parameter);

            try
            {
                return(BitArrayExtension.GetBitArray(System.Convert.ToInt32(bitArr), len));
            }
            catch (Exception e)
            {
                return(new BitArray(0));
            }
        }
Beispiel #11
0
        private BitArray FindMaxDivider() //19
        {
            var num     = FirstOperand.ToInt();
            int divider = 0;

            for (int i = 0; i < 10; i++)
            {
                if (num % (int)Math.Pow(2, i) == 0)
                {
                    divider = i;
                }
            }
            ThirdOperand = BitArrayExtension.GetBitArray(divider, OperandLenght);
            return(ThirdOperand);
        }
Beispiel #12
0
 public Command(string command, int id = 0)
 {
     try
     {
         int[] splitedCommand = command.Split(' ').Select(i => Convert.ToInt32(i)).ToArray();
         if (splitedCommand.Length != 4)
         {
             throw new CommandException(this, "Incorrect Command Input");
         }
         ThirdOperand  = BitArrayExtension.GetBitArray(splitedCommand[0], OperandLenght);
         SecondOperand = BitArrayExtension.GetBitArray(splitedCommand[1], OperandLenght);
         FirstOperand  = BitArrayExtension.GetBitArray(splitedCommand[2], OperandLenght);
         Operation     = BitArrayExtension.GetBitArray(splitedCommand[3], OperationLenght);
         CommandId     = id;
         Operations    = InitializeOperations();
     }
     catch (Exception)
     {
         new Command(id);
     }
 }
Beispiel #13
0
        public BitArray GetFullCommand()
        {
            var newBitArray = BitArrayExtension.GetBitArray(Convert.ToInt32(GetBinaryStringCommand(), 2), OperandLenght);

            return(newBitArray);
        }