public static bool TryWriteHalfBigEndian(Span <byte> destination, Half value)
        {
            if (BitConverter.IsLittleEndian)
            {
                short tmp = ReverseEndianness(BitConverter.HalfToInt16Bits(value));
                return(MemoryMarshal.TryWrite(destination, ref tmp));
            }

            return(MemoryMarshal.TryWrite(destination, ref value));
        }
Beispiel #2
0
        public static void HalfToInt16Bits()
        {
            Half  input  = (Half)12.34;
            short result = BitConverter.HalfToInt16Bits(input);

            Assert.Equal((short)18988, result);
            Half roundtripped = BitConverter.Int16BitsToHalf(result);

            Assert.Equal(input, roundtripped);
        }
 public static void WriteHalfBigEndian(Span <byte> destination, Half value)
 {
     if (BitConverter.IsLittleEndian)
     {
         short tmp = ReverseEndianness(BitConverter.HalfToInt16Bits(value));
         MemoryMarshal.Write(destination, ref tmp);
     }
     else
     {
         MemoryMarshal.Write(destination, ref value);
     }
 }