Exemple #1
0
        public static byte[] Encode(Float40 n)
        {
            var bytes = new byte[5];

            bytes[0] = (byte)n.exp;
            Array.Copy(BitConverter.GetBytes((uint)n.mantissa), 0, bytes, 1, 4);
            if (n.negative)
            {
                bytes[4] |= 128;
            }
            return(bytes);
        }
Exemple #2
0
        public static Float40 Decode(byte[] bytes)
        {
            if (bytes.Length < 5)
            {
                throw new ArgumentException("Source array is not long enough", nameof(bytes));
            }
            var n = new Float40();

            n.exp = (sbyte)bytes[0];
            long t = BitConverter.ToUInt32(bytes, 1);

            n.mantissa = (t & 0x7fffffffL);
            n.negative = (t & 0x80000000L) != 0;
            return(n);
        }