Ejemplo n.º 1
0
        public Returnstack convertTo(String wert)
        {
            if (!this.analyse (wert)) {
                Returnstack result = new Returnstack ("Falsche Syntax!\nEs sind nur die Zeichen '0-9' und '-' erlaubt.");
                result.addStep ("Analyse ergabe Fehler in der Syntax.");
                return result;
            }

            int vorzeichen = 0;
            if (wert [0] == '-') {
                wert = wert.Remove (0, 1);
                vorzeichen = 1;
            }
            Returnstack convert = new Dezimal ().convertToBin (wert) ;

            if(vorzeichen == 1){
                convert.setResult( "1" + new Dualoperationen ().addieren (new Dualoperationen ().invert (convert.getResult ()), "1"));
            } else {
                convert.setResult( "0" + convert.getResult ());
            }
            return convert;
        }
        private Returnstack convert(String type)
        {
            Returnstack convert = new Returnstack ();
            convert.addStep ("Prüfen der ausgangs Parameter;");

            if (wert == "") {
                convert.setResult ("Kein Wert");
                return convert;
            }
            if (bias == "") {
                convert.setResult ("Missing Bias");
                return convert;
            }
            if (new Regex ("[^0-9]").Match (this.bias).Success) {
                convert.setResult ("Wrong Syntax");
                return convert;
            }

            switch (type) {

                case "to":
                    if (new Regex ("[^0-9\\-]").Match (this.wert).Success) {
                        convert.setResult ("Wrong Syntax");
                        return convert;
                    }

                    String erg = ((int)(Double.Parse (wert) + Double.Parse (bias))).ToString ();
                    convert = new Dezimal ().convertToBin (erg);
                    return convert;

                case "from":

                    if (new Regex ("[^0-1]").Match (this.wert).Success) {
                        convert.setResult ("Wrong Syntax");
                        return convert;
                    }

                    convert = new Binaer ().convertToDez (wert);
                    convert.setResult (((int)(Double.Parse (convert.getResult ()) - Double.Parse (bias))).ToString ());
                    return convert;
                default :
                    return convert;
            }
        }