/// <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()); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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))); }
/// <inheritdoc /> public int CompareTo(FixedBytes other) { return(other == null ? 1 : ByteArrayUtils.CompareUnsignedBigEndian(this.UnderlyingBytes, other.UnderlyingBytes)); }