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;
            }
        }
Ejemplo n.º 2
0
        public Returnstack convertFrom(String wert)
        {
            if (!this.analyse (wert)) {
                Returnstack result = new Returnstack ("Falsche Syntax!\nEs sind nur die Zeichen '0-1' erlaubt.");
                result.addStep ("Analyse ergabe Fehler in der Syntax.");
                return result;
            }

            Returnstack convert ;

            if (wert [0] == '1') {
                wert = wert.Remove (0, 1);
                convert = new Binaer ().convertToDez (new Dualoperationen ().invert (wert));
                convert.setResult( "-" + (int.Parse (convert.getResult ()) + 1).ToString ());
            } else {
                convert = new Binaer ().convertToDez (wert);
            }
            return convert;
        }
Ejemplo n.º 3
0
        public Returnstack convertFrom(String wert)
        {
            if(!this.analyse (wert)){
                Returnstack result = new Returnstack("Falsche Syntax!\nEs sind nur die Zeichen '0-1' und ',' erlaubt.");
                result.addStep("Analyse ergabe Fehler in der Syntax.");
                return result;
            }

            this.getParts (wert);
            String[] splited = wert.Split (',');

            Returnstack part1 = new Binaer ().convertToDez (splited [0]);
            if (this.parts == 2) {
                Returnstack part2 = new Binaer ().convertToDez (splited [1]);
                part2.setResult ((Double.Parse (part2.getResult ()) / (int)Math.Pow (2, splited [1].Length)).ToString ().Split (',') [1]);
                part1 += "," + part2.getResult ();
            } else
                part1 += ",0";
            return part1;
        }