System.Net.BigIntegerExtensions.PositiveReverse C# (CSharp) Method

PositiveReverse() public static method

Reverse a Positive BigInteger ONLY Bitwise ~ operator Input : FF FF FF FF Width : 4 Result : 00 00 00 00 Input : 00 00 00 00 Width : 4 Result : FF FF FF FF Input : FF FF FF FF Width : 8 Result : FF FF FF FF 00 00 00 00 Input : 00 00 00 00 Width : 8 Result : FF FF FF FF FF FF FF FF
public static PositiveReverse ( this input, int width ) : System.Numerics.BigInteger
input this
width int
return System.Numerics.BigInteger
        public static BigInteger PositiveReverse(this BigInteger input, int width)
        {
            var result = new List<byte>();
            var bytes = input.ToByteArray();
            var work = new byte[width];
            Array.Copy(bytes, 0, work, 0, bytes.Length - 1); // Length -1 : positive BigInteger

            for (int i = 0; i < work.Length; i++) {
                result.Add((byte)(~work[i]));
            }
            result.Add(0); // positive BigInteger
            return new BigInteger(result.ToArray());
        }