public byte[] ConvertTo(object value)
        {
            TypeInterpreter.CheckArgument <decimal>(value);
            int[] bits = decimal.GetBits((decimal)value);

            var bytes = new byte[16];

            int scale = (bits[3] >> 16) & 31;

            byte[] scaleB = BitConverter.GetBytes(scale);
            byte[] lowB   = BitConverter.GetBytes(bits[0]);
            byte[] midB   = BitConverter.GetBytes(bits[1]);
            byte[] highB  = BitConverter.GetBytes(bits[2]);

            Array.Copy(lowB, 0, bytes, 0, 4);
            Array.Copy(midB, 0, bytes, 4, 4);
            Array.Copy(highB, 0, bytes, 8, 4);
            Array.Copy(scaleB, 0, bytes, 12, 4);

            if ((decimal)value < 0)
            {
                for (int i = 0; i < 12; i++)
                {
                    bytes[i] = (byte)~bytes[i];
                }
                bytes[0] += 1;
            }
            Array.Reverse(bytes);
            return(bytes);
        }
示例#2
0
 public byte[] ConvertTo(object value)
 {
     TypeInterpreter.CheckArgument <BigInteger>(value);
     return(((BigInteger)value).ToByteArray());
 }
示例#3
0
 public byte[] ConvertTo(object value)
 {
     TypeInterpreter.CheckArgument <byte[]>(value);
     return((byte[])value);
 }