public void ApplyFloatWithLittleEndianShouldNoOp() { const float input = 12; var result = EndianessConverter.ApplyFloat(ByteOrder.LittleEndian, input); Assert.AreEqual(input, result); }
public void ApplyFloatWithBigEndianShouldReverseBytes() { const float input = 12; var result = EndianessConverter.ApplyFloat(ByteOrder.BigEndian, input); float expected = BitConverter.ToSingle(BitConverter.GetBytes(input).Reverse().ToArray(), 0); Assert.AreEqual(expected, result); }
public void ShouldPutFloatBigEndian() { const float value = float.MaxValue - 1; const int index = 0; _directBuffer.FloatPutBigEndian(index, value); var expected = EndianessConverter.ApplyFloat(ByteOrder.BigEndian, value); Assert.AreEqual(expected, *(float *)(_pBuffer + index)); }
public void ShouldGetFloatBigEndian() { const float value = float.MaxValue - 1; const int index = 0; var bytes = BitConverter.GetBytes(value); Array.Copy(bytes, 0, _buffer, index, 4); var result = _directBuffer.FloatGetBigEndian(index); var expected = EndianessConverter.ApplyFloat(ByteOrder.BigEndian, value); Assert.AreEqual(expected, result); }
public void PutFloat(int index, float value, ByteOrder byteOrder) { BoundsCheck0(index, BitUtil.SIZE_OF_FLOAT); value = EndianessConverter.ApplyFloat(byteOrder, value); *(float *)(_pBuffer + index) = value; }
public float GetFloat(int index, ByteOrder byteOrder) { BoundsCheck0(index, BitUtil.SIZE_OF_FLOAT); return(EndianessConverter.ApplyFloat(byteOrder, *(float *)(_pBuffer + index))); }