Beispiel #1
0
        public static void FloatToBytes(float value, out byte b0, out byte b1, out byte b2, out byte b3)
        {
#if FAST_CONVERT
            Float2Bytes f2b = default(Float2Bytes);
            f2b.Float = value;
            b0        = f2b.Byte0;
            b1        = f2b.Byte1;
            b2        = f2b.Byte2;
            b3        = f2b.Byte3;
#else
            byte[] bytes = BitConverter.GetBytes(value);

#if BIG_ENDIAN
            b0 = bytes[3];
            b1 = bytes[2];
            b2 = bytes[1];
            b3 = bytes[0];
#else
            b0 = bytes[0];
            b1 = bytes[1];
            b2 = bytes[2];
            b3 = bytes[3];
#endif
#endif
        }
Beispiel #2
0
        public static float FloatFromBytes(byte b0, byte b1, byte b2, byte b3)
        {
#if FAST_CONVERT
            Float2Bytes f2b = default(Float2Bytes);
            f2b.Byte0 = b0;
            f2b.Byte1 = b1;
            f2b.Byte2 = b2;
            f2b.Byte3 = b3;
            return(f2b.Float);
#else
#if BIG_ENDIAN
            return(BitConverter.ToSingle(new byte[] { b0, b1, b2, b3 }, 0));
#else
            return(BitConverter.ToSingle(new byte[] { b3, b2, b1, b0 }, 0));
#endif
#endif
        }