Пример #1
0
        // publics
        #region FromByteArray
        public static double FromByteArray(byte[] bytes)
        {
            double wert  = 0;
            Int16  value = (Int16)Types.Word.FromBytes(bytes[1], bytes[0]);
            string txt   = Conversion.ValToBinString(value);

            wert  = Conversion.BinStringToInt(txt.Substring(4, 4)) * 100.0;
            wert += Conversion.BinStringToInt(txt.Substring(8, 4)) * 10.0;
            wert += Conversion.BinStringToInt(txt.Substring(12, 4));
            switch (txt.Substring(2, 2))
            {
            case "00":
                wert *= 0.01;
                break;

            case "01":
                wert *= 0.1;
                break;

            case "10":
                wert *= 1.0;
                break;

            case "11":
                wert *= 10.0;
                break;
            }
            return(wert);
        }
Пример #2
0
        // publics
        #region FromByteArray
        public static double FromByteArray(byte[] bytes)
        {
            byte v1 = bytes[0];
            byte v2 = bytes[1];
            byte v3 = bytes[2];
            byte v4 = bytes[3];

            if ((int)v1 + v2 + v3 + v4 == 0)
            {
                return(0.0);
            }
            else
            {
                // nun String bilden
                string txt = ValToBinString(v1) + ValToBinString(v2) + ValToBinString(v3) + ValToBinString(v4);
                // erstmal das Vorzeichen
                int    vz       = int.Parse(txt.Substring(0, 1));
                int    exd      = Conversion.BinStringToInt(txt.Substring(1, 8));
                string ma       = txt.Substring(9, 23);
                double mantisse = 1;
                double faktor   = 1.0;

                //das ist die Anzahl der restlichen bit's
                for (int cnt = 0; cnt <= 22; cnt++)
                {
                    faktor = faktor / 2.0;
                    //entspricht 2^-y
                    if (ma.Substring(cnt, 1) == "1")
                    {
                        mantisse = mantisse + faktor;
                    }
                }
                return(Math.Pow((-1), vz) * Math.Pow(2, (exd - 127)) * mantisse);
            }
        }