Example #1
0
        /// <summary>
        ///     Logical Not
        /// </summary>
        /// <param name="operand">the operand</param>
        public static FixedBytes LogicalNot(FixedBytes operand)
        {
            if (operand == null)
            {
                return(null);
            }

            return(ByteArrayUtils.BitwiseNot(operand.UnderlyingBytes)
                   .ToFixedBytes());
        }
Example #2
0
        /// <summary>
        ///     Logical Xor
        /// </summary>
        /// <param name="left">the left side operand</param>
        /// <param name="right">the right side operand</param>
        public static FixedBytes Xor(FixedBytes left,
                                     FixedBytes right)
        {
            if (left == null ||
                right == null)
            {
                return(null);
            }

            return(ByteArrayUtils.BitwiseXorBigEndian(left.UnderlyingBytes, right.GetBytes())
                   .ToFixedBytes());
        }
Example #3
0
        /// <summary>
        ///     Subtraction
        /// </summary>
        /// <param name="left">the left side operand</param>
        /// <param name="right">the right side operand</param>
        public static FixedBytes Subtract(FixedBytes left,
                                          FixedBytes right)
        {
            if (left == null ||
                right == null)
            {
                return(null);
            }

            return(ByteArrayUtils.SubtractUnsignedBigEndian(left.UnderlyingBytes, right.UnderlyingBytes)
                   .ToFixedBytes());
        }
Example #4
0
        /// <summary>
        ///     Right Shift
        /// </summary>
        /// <param name="fixedBytes">input</param>
        /// <param name="shift">the shift count</param>
        public static FixedBytes RightShift(FixedBytes fixedBytes,
                                            int shift)
        {
            if (fixedBytes == null)
            {
                return(null);
            }

            if (shift < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(shift), $"{nameof(shift)} must be 0 or greater");
            }

            return(fixedBytes.UnderlyingBytes.ShiftBitsRight(shift)
                   .ToFixedBytes());
        }
Example #5
0
 /// <summary>
 ///     Conversion from <see cref="FixedBytes" /> to <see cref="byte" /> array
 /// </summary>
 /// <param name="fixedBytes">input</param>
 public static byte[] FromFixedBytes(FixedBytes fixedBytes)
 {
     return(fixedBytes == null
                ? null
                : fixedBytes.GetBytes());
 }
Example #6
0
 /// <summary>
 ///     Similar to <see cref="Equals(FixedBytes)" />, but checks exact byte value (does not ignore 0 valued most
 ///     significant bytes)
 /// </summary>
 /// <param name="other">the value to compare to</param>
 public bool Exactly(FixedBytes other)
 {
     return(!ReferenceEquals(null, other) &&
            (ReferenceEquals(this, other) ||
             this.Exactly(other.UnderlyingBytes)));
 }
Example #7
0
 /// <inheritdoc />
 public int CompareTo(FixedBytes other)
 {
     return(other == null
                ? 1
                : ByteArrayUtils.CompareUnsignedBigEndian(this.UnderlyingBytes, other.UnderlyingBytes));
 }