public void LittleEndianBitConverter_Decimal() { const int n = sizeof(Decimal); const Decimal pos = 3.1415926535897932384626433833m; const Decimal zero = 0; const Decimal neg = -pos; var posRepr = GetCanonicalRepresentation(pos); var negRepr = GetCanonicalRepresentation(neg); // -------------------------------------------------------------- var buffer = new byte[n]; LittleEndianBitConverter.FillBytes(pos, buffer); Assert.IsTrue(buffer.SequenceEqual(posRepr)); Assert.IsTrue(LittleEndianBitConverter.GetBytes(pos).SequenceEqual(buffer)); Assert.AreEqual(pos, LittleEndianBitConverter.ToDecimal(buffer)); LittleEndianBitConverter.FillBytes(zero, buffer); Assert.IsTrue(buffer.SequenceEqual(new byte[n])); Assert.IsTrue(LittleEndianBitConverter.GetBytes(zero).SequenceEqual(buffer)); Assert.AreEqual(zero, LittleEndianBitConverter.ToDecimal(buffer)); LittleEndianBitConverter.FillBytes(neg, buffer); Assert.IsTrue(buffer.SequenceEqual(negRepr)); Assert.IsTrue(LittleEndianBitConverter.GetBytes(neg).SequenceEqual(buffer)); Assert.AreEqual(neg, LittleEndianBitConverter.ToDecimal(buffer)); }