示例#1
0
        public byte[] ConvertTo(object value)
        {
            TypeCodec.CheckArgument <decimal>(value);
            var decimalValue = (decimal)value;

            int[] bits = decimal.GetBits(decimalValue);

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

            byte[] scaleBytes = BeConverter.GetBytes(scale);

            var bigintBytes = new byte[13]; // 13th byte is for making sure that the number is positive

            Buffer.BlockCopy(bits, 0, bigintBytes, 0, 12);

            var bigInteger = new BigInteger(bigintBytes);

            if (decimalValue < 0)
            {
                bigInteger = -bigInteger;
            }

            bigintBytes = bigInteger.ToByteArray();
            Array.Reverse(bigintBytes);

            var resultBytes = new byte[scaleBytes.Length + bigintBytes.Length];

            Array.Copy(scaleBytes, resultBytes, scaleBytes.Length);
            Array.Copy(bigintBytes, 0, resultBytes, scaleBytes.Length, bigintBytes.Length);
            return(resultBytes);
        }
示例#2
0
 public byte[] ConvertTo(object value)
 {
     TypeCodec.CheckArgument <byte[]>(value);
     return((byte[])value);
 }
示例#3
0
 public byte[] ConvertTo(object value)
 {
     TypeCodec.CheckArgument <BigInteger>(value);
     return(((BigInteger)value).ToByteArray());
 }