//שחזור מפענח
        public void mefaanehAfterSave(int size, int ca, int cb, int cc, int cd, int ya, int yb, int yc, int yd, int hc, int hy, int gridh, int gridw, int grida, int gridb, int gridc, int gridd, int[] arr)
        {
            currDeviceResType = ResultType.ArrayRes;
            rtype             = "mefaaneah";
            binaributton[] binaributtons = new binaributton[(int)Math.Pow(2, size)];
            Image[]        carray        = new Image[size];

            for (int i = 0; i < (int)Math.Pow(2, size); i++)
            {
                binaributtons[i] = new binaributton(ya, yb, yc, yd, i, type);
                yb += hy; yd -= hy;
                grid1.Children.Add(binaributtons[i]);
            }
            for (int i = 0; i < size; i++)
            {
                carray[i]        = new Image();
                carray[i].Margin = new Thickness(ca, cb, cc, cd);
                cb += hc; cd -= hc;
                addToImages(carray, i, arr);
                grid1.Children.Add(carray[i]);
            }
            // set expected result
            BL.Class1.refOutputBinaryArr = BL.Class1.Decoder(BL.Class1.rndInputBinaryArr, BL.Class1.refOutputBinaryArr);

            grid2.Height = gridh;
            grid2.Width  = gridw;
            grid2.Margin = new Thickness(grida, gridb, gridc, gridd);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/מפענח " + size + " כניסות.png", UriKind.Relative));
            myBrush.ImageSource = image.Source;
            grid2.Background    = myBrush;
        }
        //חצי מחבר
        public void illuaddhzmechaber(int numof)
        {
            rsize = numof;

            if (numof == 2)
            {
                rtype = "hmechaber";

                // מערך הכניסות
                binaributton[] binaributtons = new binaributton[2];
                for (int i = 1; i >= 0; i--)
                {
                    binaributtons[i] = new binaributton(i, type);

                    grid11.Children.Add(binaributtons[i]);
                }
                binaributtons[1].Margin = new Thickness(352, 56, 407, 341);
                binaributtons[0].Margin = new Thickness(413, 56, 346, 341);
                grid2.Height            = 178;
                grid2.Width             = 198;
                grid2.Margin            = new Thickness(284, 80, 0, 0);
                ImageBrush myBrush = new ImageBrush();
                Image      image   = new Image();
                image.Source        = new BitmapImage(new Uri(@"../../IMG1/חציי מחבר.png", UriKind.Relative));
                myBrush.ImageSource = image.Source;
                grid2.Background    = myBrush;
            }
            //מחבר מלא....CIN
            else
            {
                rtype = "mechaber";


                //CIN מערך הכניסות-במקרה שהמחבר מלא תהיינה 3 כניסות שאחת מהן היא -האיבר האחרון במערך
                binaributton[] binaributtons = new binaributton[3];
                for (int i = 0; i < 3; i++)
                {
                    binaributtons[i] = new binaributton(i, type);

                    grid11.Children.Add(binaributtons[i]);
                }

                binaributtons[0].Margin = new Thickness(340, 59, 419, 341);
                binaributtons[1].Margin = new Thickness(392, 59, 367, 341);
                binaributtons[2].Margin = new Thickness(457, 59, 302, 341);
                grid2.Height            = 178;
                grid2.Width             = 198;
                grid2.Margin            = new Thickness(284, 80, 0, 0);
                ImageBrush myBrush = new ImageBrush();
                Image      image   = new Image();
                image.Source        = new BitmapImage(new Uri(@"../../IMG1/מחבר מלאא.png", UriKind.Relative));
                myBrush.ImageSource = image.Source;
                grid2.Background    = myBrush;
            }
        }
        //משווה גודל  משוחזר
        public void mgAfterSave(int size, int hc, int c1a, int c1b, int c1c, int c1d, int c2a, int c2b, int c2c, int c2d, int [] arr1, int[] arr2)
        {
            rtype = "mg";
            binaributton[] binaributtons = new binaributton[3];
            Image[]        carray1       = new Image[size];
            Image[]        carray2       = new Image[size];
            //////////////////////////////////////////////////////////
            int ya = 328, yc = 435;
            int ca = 335, cc = 415;

            for (int i = 0; i < 3; i++)
            {
                binaributtons[i] = new binaributton(ya, 222, yc, 119, i, 0);
                ya += 44; yc -= 44;
                grid1.Children.Add(binaributtons[i]);
            }

            for (int i = 0; i < size; i++)
            {
                carray1[i]        = new Image();
                carray1[i].Margin = new Thickness(c1a, c1b, c1c, c1d);
                c1a += hc; c1c -= hc;
                addToImages(carray1, i, arr1);
                grid1.Children.Add(carray1[i]);
            }


            for (int i = 0; i < size; i++)
            {
                carray2[i]        = new Image();
                carray2[i].Margin = new Thickness(c2a, c2b, c2c, c2d);
                c2a += hc; c2c -= hc;
                addToImages(carray2, i, arr2);
                grid1.Children.Add(carray2[i]);
            }
            //Height = "166" Margin = "307,82,0,0" VerticalAlignment = "Top" Width = "164"
            grid2.Height = 166;
            grid2.Width  = 164;
            grid2.Margin = new Thickness(307, 82, 0, 0);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/משווה גודל.png", UriKind.Relative));
            myBrush.ImageSource = image.Source;
            grid2.Background    = myBrush;
            // set expected result
            BL.Class1.refOutputBinaryArr = BL.Class1.MagnitudeComparator(BL.Class1.rndInputBinaryArr,
                                                                         BL.Class1.rndInput2BinaryArr,
                                                                         BL.Class1.refOutputBinaryArr);
        }
        public void merabevAfterSave(int size, int ca, int cb, int cc, int cd, int cma, int cmb, int cmc, int cmd, int hc, int hcm, int gridh, int gridw, int grida, int gridb, int gridc, int gridd, int ya, int yb, int yc, int yd, int[] arr1, int[] arr2)
        {
            currDeviceResType = ResultType.SingleRes;
            rtype             = "merabev";
            binaributton y = new binaributton(ya, yb, yc, yd, 0, type);

            grid1.Children.Add(y);
            Image[] c  = new Image[size];                   //multpilexer select
            Image[] cm = new Image[(int)Math.Pow(2, size)]; //multiplexer data in
            for (int i = 0; i < (int)Math.Pow(2, size); i++)
            {
                cm[i]        = new Image();
                cm[i].Margin = new Thickness(cma, cmb, cmc, cmd);
                cmb         += hcm; cmd -= hcm;
                addToImages(cm, i, arr2);
                grid1.Children.Add(cm[i]);
            }
            //multpilexer select
            for (int i = 0; i < size; i++)
            {
                c[i]        = new Image();
                c[i].Margin = new Thickness(ca, cb, cc, cd);
                ca         -= hc; cc += hc;
                addToImages(c, i, arr1, 1);
                grid1.Children.Add(c[i]);
            }
            // set expected result
            BL.Class1.refOutputBinary = BL.Class1.Multiplexer(BL.Class1.rndInput2BinaryArr, BL.Class1.rndInputBinaryArr);

            grid2.Height = gridh;
            grid2.Width  = gridw;
            grid2.Margin = new Thickness(grida, gridb, gridc, gridd);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/מרבב " + size + ".png", UriKind.Relative));
            myBrush.ImageSource = image.Source;

            grid2.Background = myBrush;
            // set default output
            BL.Class1.outputBinary = 0;
        }
        // פונקציה להוספת משווה גודל

        public void illuaddmg(int size, int hc, int c1a, int c1b, int c1c, int c1d, int c2a, int c2b, int c2c, int c2d)
        {
            binaributton[] binaributtons1 = new binaributton[size];
            binaributton[] binaributtons2 = new binaributton[size];
            Image[]        carray = new Image[3];
            int            ca = 309, cc = 444;

            for (int i = 0; i < size; i++)
            {
                binaributtons1[i] = new binaributton(c1a, c1b, c1c, c1d, 0, 0);
                c1a += hc; c1c -= hc;
                grid11.Children.Add(binaributtons1[i]);
            }

            for (int i = 0; i < size; i++)
            {
                binaributtons2[i] = new binaributton(c2a, c2b, c2c, c2d, 0, 0);
                c2a += hc; c2c -= hc;
                grid11.Children.Add(binaributtons2[i]);
            }


            for (int i = 0; i < 3; i++)
            {
                carray[i]        = new Image();
                carray[i].Margin = new Thickness(ca, 235, cc, 120);
                ca += 52; cc -= 52;
                //בפתרון נוסיף את המערך שכבר נוצר!!!
                //grid11.Children.Add(carray[i]);
            }


            grid2.Height = 178;
            grid2.Width  = 198;
            grid2.Margin = new Thickness(284, 80, 0, 0);
            ImageBrush myBrush = new ImageBrush();
            Image      image = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/משווה גודל.png", UriKind.Relative));
            myBrush.ImageSource = image.Source;
            grid2.Background    = myBrush;
        }
        //מקודד
        public void addmkdd(int size, int ca, int cb, int cc, int cd, int ya, int yb, int yc, int yd, int hc, int hy, int gridh, int gridw, int grida, int gridb, int gridc, int gridd)
        {
            currDeviceResType = ResultType.ArrayRes;
            rtype             = "mkdd";
            binaributton[] binaributtons = new binaributton[size];
            Image[]        carray        = new Image[(int)Math.Pow(2, size)];
            int[]          tempNarray    = new int[(int)Math.Pow(2, size)];
            for (int i = 0; i < size; i++)
            {
                binaributtons[i] = new binaributton(ya, yb, yc, yd, i, type);
                yb += hy; yd -= hy;
                grid1.Children.Add(binaributtons[i]);
            }

            for (int i = 0; i < (int)Math.Pow(2, size); i++)
            {
                carray[i]        = new Image();
                carray[i].Margin = new Thickness(ca, cb, cc, cd);
                cb += hc; cd -= hc;
                random(carray, i, tempNarray, 0);
                grid1.Children.Add(carray[i]);
            }

            //// set expected result
            //BL.Class1.refOutputBinaryArr = BL.Class1.Decoder(BL.Class1.rndInputBinaryArr, BL.Class1.refOutputBinaryArr);
            currentNArray = tempNarray;
            currentType   = "encoder";

            grid2.Height = gridh;
            grid2.Width  = gridw;
            grid2.Margin = new Thickness(grida, gridb, gridc, gridd);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/מקודד " + size + ".png", UriKind.Relative));
            myBrush.ImageSource = image.Source;


            grid2.Background = myBrush;
        }
        //מרבב
        public void illuaddmerabev(int size, int ca, int cb, int cc, int cd, int cma, int cmb, int cmc, int cmd, int hc, int hcm, int gridh, int gridw, int grida, int gridb, int gridc, int gridd)
        {
            rtype = "merabev";
            rsize = size;


            binaributton[] binaributtonsc  = new binaributton[size];
            binaributton[] binaributtonscm = new binaributton[(int)Math.Pow(2, size)];
            // input data
            for (int i = 0; i < (int)Math.Pow(2, size); i++)
            {
                binaributtonscm[i] = new binaributton(cma, cmb, cmc, cmd, i, type);

                cmb += hcm; cmd -= hcm;

                grid11.Children.Add(binaributtonscm[i]);
            }
            // input select
            for (int i = size - 1; i >= 0; i--)
            {
                binaributtonsc[i] = new binaributton(ca, cb, cc, cd, i, type + 1);

                ca += hc; cc -= hc;

                grid11.Children.Add(binaributtonsc[i]);
            }

            grid2.Height = gridh;
            grid2.Width  = gridw;
            grid2.Margin = new Thickness(grida, gridb, gridc, gridd);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/מרבב " + size + ".png", UriKind.Relative));
            myBrush.ImageSource = image.Source;

            grid2.Background = myBrush;
            // set default output
            //BL.Class1.outputBinary = 0;
        }
        //מקודד
        public void illuaddmkdd(int size, int ca, int cb, int cc, int cd, int hc, int gridh, int gridw, int grida, int gridb, int gridc, int gridd)
        {
            rtype = "mkdd";
            rsize = size;
            binaributton[] binaributtons = new binaributton[(int)Math.Pow(2, size)];

            for (int i = 0; i < (int)Math.Pow(2, size); i++)
            {
                binaributtons[i] = new binaributton(ca, cb, cc, cd, i, type);
                cb += hc; cd -= hc;
                grid11.Children.Add(binaributtons[i]);
            }

            grid2.Height = gridh;
            grid2.Width  = gridw;
            grid2.Margin = new Thickness(grida, gridb, gridc, gridd);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/מקודד " + size + ".png", UriKind.Relative));
            myBrush.ImageSource = image.Source;
            grid2.Background    = myBrush;
        }
        // פונקציה להוספת משווה גודל
        public void addmg(int size, int hc, int c1a, int c1b, int c1c, int c1d, int c2a, int c2b, int c2c, int c2d)
        {
            rtype = "mg";
            binaributton[] binaributtons   = new binaributton[3];
            Image[]        carray1         = new Image[size];
            Image[]        carray2         = new Image[size];
            int[]          tempNarrayForC1 = new int[size];
            int[]          tempNarrayForC2 = new int[size];
            //////////////////////////////////////////////////////////
            int ya = 328, yc = 435;
            int ca = 335, cc = 415;

            for (int i = 0; i < 3; i++)
            {
                binaributtons[i] = new binaributton(ya, 222, yc, 119, i, 0);
                ya += 44; yc -= 44;
                grid1.Children.Add(binaributtons[i]);
            }

            for (int i = 0; i < size; i++)
            {
                carray1[i]        = new Image();
                carray1[i].Margin = new Thickness(c1a, c1b, c1c, c1d);
                c1a += hc; c1c -= hc;
                random(carray1, i, tempNarrayForC1);
                grid1.Children.Add(carray1[i]);
            }


            for (int i = 0; i < size; i++)
            {
                carray2[i]        = new Image();
                carray2[i].Margin = new Thickness(c2a, c2b, c2c, c2d);
                c2a += hc; c2c -= hc;
                random(carray2, i, tempNarrayForC2);
                grid1.Children.Add(carray2[i]);
            }
            int[] narrayComb = new int[2 * size];
            int   k;

            for (k = 0; k < size; k++)
            {
                narrayComb[k] = tempNarrayForC1[k];
            }
            narrayComb[k] = -2;
            k++;
            int f = 0;

            for (int t = k; t < 2 * size; t++)
            {
                narrayComb[t] = tempNarrayForC2[f];
                f++;
            }
            currentNArray = narrayComb;
            currentType   = "Compares size";
            //Height = "166" Margin = "307,82,0,0" VerticalAlignment = "Top" Width = "164"
            grid2.Height = 166;
            grid2.Width  = 164;
            grid2.Margin = new Thickness(307, 82, 0, 0);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/משווה גודל.png", UriKind.Relative));
            myBrush.ImageSource = image.Source;
            grid2.Background    = myBrush;
            // set expected result
            BL.Class1.refOutputBinaryArr = BL.Class1.MagnitudeComparator(BL.Class1.rndInputBinaryArr,
                                                                         BL.Class1.rndInput2BinaryArr,
                                                                         BL.Class1.refOutputBinaryArr);
        }
        //מרבב
        public void addmerabev(int size, int ca, int cb, int cc, int cd, int cma, int cmb, int cmc, int cmd, int hc, int hcm, int gridh, int gridw, int grida, int gridb, int gridc, int gridd, int ya, int yb, int yc, int yd)
        {
            currDeviceResType = ResultType.SingleRes;
            rtype             = "merabev";
            binaributton y = new binaributton(ya, yb, yc, yd, 0, type);

            grid1.Children.Add(y);
            ///////////////////////////////////////////////////////
            Image[] c               = new Image[size];                   //multpilexer select
            Image[] cm              = new Image[(int)Math.Pow(2, size)]; //multiplexer data in
            int []  tempNarrayForC  = new int[size];
            int[]   tempNarrayForCm = new int[(int)Math.Pow(2, size)];
            ///////////////////////////////////////////////////////
            // data in
            for (int i = 0; i < (int)Math.Pow(2, size); i++)
            {
                cm[i]        = new Image();
                cm[i].Margin = new Thickness(cma, cmb, cmc, cmd);
                cmb         += hcm; cmd -= hcm;
                random(cm, i, tempNarrayForCm);
                grid1.Children.Add(cm[i]);
            }
            //multpilexer select
            for (int i = 0; i < size; i++)
            {
                c[i]        = new Image();
                c[i].Margin = new Thickness(ca, cb, cc, cd);
                ca         -= hc; cc += hc;
                random(c, i, tempNarrayForC, 1);
                grid1.Children.Add(c[i]);
            }
            int[] NcarrayComb = new int[(int)Math.Pow(2, size) + size + 1];
            int   k;

            for (k = 0; k < size; k++)
            {
                NcarrayComb[k] = tempNarrayForC[k];
            }

            NcarrayComb[k] = -2;
            k++;
            int f = 0;

            for (int t = k; t < (int)Math.Pow(2, size) + size; t++)
            {
                NcarrayComb[t] = tempNarrayForCm[f];
                f++;
            }
            currentNArray = NcarrayComb;
            currentType   = "Multiplexer";
            // set expected result
            BL.Class1.refOutputBinary = BL.Class1.Multiplexer(BL.Class1.rndInput2BinaryArr, BL.Class1.rndInputBinaryArr);

            grid2.Height = gridh;
            grid2.Width  = gridw;
            grid2.Margin = new Thickness(grida, gridb, gridc, gridd);
            ImageBrush myBrush = new ImageBrush();
            Image      image   = new Image();

            image.Source        = new BitmapImage(new Uri(@"../../IMG1/מרבב " + size + ".png", UriKind.Relative));
            myBrush.ImageSource = image.Source;

            grid2.Background = myBrush;
            // set default output
            BL.Class1.outputBinary = 0;
        }
        //מחבר משוחזר
        public void hzmechaberafterSave(int numof, int[] arr)
        {
            currDeviceResType = ResultType.ArrayRes;
            rsize             = numof;
            if (numof == 2)
            {
                rtype = "hmechaber";
                //C-שארית Z-תוצאה

                binaributton z = new binaributton(381, 237, 383, 131, 0, type);
                grid1.Children.Add(z);
                binaributton c = new binaributton(269, 237, 495, 132, 1, type);
                grid1.Children.Add(c);

                // מערך הכניסות
                Image[] carray = new Image[2];
                ////////////////////////////////////////////////////////////
                for (int i = 0; i < 2; i++)
                {
                    carray[i] = new Image();
                    addToImages(carray, i, arr);
                    grid1.Children.Add(carray[i]);
                }
                carray[0].Margin = new Thickness(401, 52, 347, 330);
                carray[1].Margin = new Thickness(340, 52, 408, 330);
                grid2.Height     = 165;
                grid2.Width      = 203;
                grid2.Margin     = new Thickness(276, 84, 0, 0);
                ImageBrush myBrush = new ImageBrush();
                Image      image   = new Image();
                image.Source        = new BitmapImage(new Uri(@"../../IMG1/חציי מחבר.png", UriKind.Relative));
                myBrush.ImageSource = image.Source;
                grid2.Background    = myBrush;
            }
            //מחבר מלא....CIN
            else
            {
                rtype = "mechaber";
                binaributton z = new binaributton(364, 237, 400, 131, 0, type);
                grid1.Children.Add(z);
                binaributton c = new binaributton(269, 230, 495, 139, 1, type);
                grid1.Children.Add(c);

                //CIN מערך הכניסות-במקרה שהמחבר מלא תהיינה 3 כניסות שאחת מהן היא -האיבר האחרון במערך
                Image[] carray = new Image[3];

                /////////////////////////////////////////////////////////
                for (int i = 0; i < 3; i++)
                {
                    carray[i] = new Image();
                    addToImages(carray, i, arr);
                    grid1.Children.Add(carray[i]);
                }

                carray[0].Margin = new Thickness(446, 52, 302, 330);
                carray[1].Margin = new Thickness(381, 52, 367, 330);
                carray[2].Margin = new Thickness(328, 52, 420, 330);
                grid2.Height     = 165;
                grid2.Width      = 203;
                grid2.Margin     = new Thickness(276, 84, 0, 0);
                ImageBrush myBrush = new ImageBrush();
                Image      image   = new Image();
                image.Source        = new BitmapImage(new Uri(@"../../IMG1/מחבר מלאא.png", UriKind.Relative));
                myBrush.ImageSource = image.Source;
                grid2.Background    = myBrush;
            }
            // set expected result

            BL.Class1.refOutputBinaryArr = BL.Class1.Adder(BL.Class1.rndInputBinaryArr, BL.Class1.refOutputBinaryArr, rsize);
        }