avt.DynamicFlashRotator.Net.RegCore.Cryptography.BigInteger.getBytes C# (CSharp) Method

getBytes() public method

public getBytes ( ) : byte[]
return byte[]
        public byte[] getBytes()
        {
            int numBits = bitCount();

            int numBytes = numBits >> 3;
            if ((numBits & 0x7) != 0)
                numBytes++;

            byte[] result = new byte[numBytes];

            //Console.WriteLine(result.Length);

            int pos = 0;
            uint tempVal, val = data[dataLength - 1];

            // This section includes bugfix for 'leading 0's' bug
            if ((tempVal = (val >> 24 & 0xFF)) != 0)
                result[pos++] = (byte)tempVal;
            if ((tempVal = (val >> 16 & 0xFF)) != 0 || pos != 0)
                result[pos++] = (byte)tempVal;
            if ((tempVal = (val >> 8 & 0xFF)) != 0 || pos != 0)
                result[pos++] = (byte)tempVal;
            if ((tempVal = (val & 0xFF)) != 0 || pos != 0)
                result[pos++] = (byte)tempVal;
            // End bugfix

            for (int i = dataLength - 2; i >= 0; i--, pos += 4) {
                val = data[i];
                result[pos + 3] = (byte)(val & 0xFF);
                val >>= 8;
                result[pos + 2] = (byte)(val & 0xFF);
                val >>= 8;
                result[pos + 1] = (byte)(val & 0xFF);
                val >>= 8;
                result[pos] = (byte)(val & 0xFF);
            }

            return result;
        }

Usage Example

示例#1
0
 // Convert a big integer to a base 64 string
 private string bigint_to_b64(BigInteger bi)
 {
     byte[] b = bi.getBytes();
     return Convert.ToBase64String(b);
 }
All Usage Examples Of avt.DynamicFlashRotator.Net.RegCore.Cryptography.BigInteger::getBytes