BitSharper.Utils.DecodeCompactBits C# (CSharp) Method

DecodeCompactBits() static private method

static private DecodeCompactBits ( long compact ) : BigInteger
compact long
return Org.BouncyCastle.Math.BigInteger
        internal static BigInteger DecodeCompactBits(long compact)
        {
            var size = (byte) (compact >> 24);
            var bytes = new byte[4 + size];
            bytes[3] = size;
            if (size >= 1) bytes[4] = (byte) (compact >> 16);
            if (size >= 2) bytes[5] = (byte) (compact >> 8);
            if (size >= 3) bytes[6] = (byte) (compact >> 0);
            return DecodeMpi(bytes);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Returns the difficulty target as a 256 bit value that can be compared to a SHA-256 hash. Inside a block the
        /// target is represented using a compact form. If this form decodes to a value that is out of bounds,
        /// an exception is thrown.
        /// </summary>
        /// <exception cref="VerificationException"/>
        public BigInteger GetDifficultyTargetAsInteger()
        {
            var target = Utils.DecodeCompactBits(_difficultyTarget);

            if (target.CompareTo(BigInteger.Zero) <= 0 || target.CompareTo(Params.ProofOfWorkLimit) > 0)
            {
                throw new VerificationException("Difficulty target is bad: " + target);
            }
            return(target);
        }
All Usage Examples Of BitSharper.Utils::DecodeCompactBits