public double GetDifficulty(ChainedBlock blockindex) { // Floating point number that is a multiple of the minimum difficulty, // minimum difficulty = 1.0. if (blockindex == null) { if (this.ChainIndex.Tip == null) { return(1.0); } else { blockindex = BlockValidator.GetLastBlockIndex(this.ChainIndex.Tip, false); } } var nShift = (blockindex.Header.Bits >> 24) & 0xff; double dDiff = (double)0x0000ffff / (double)(blockindex.Header.Bits & 0x00ffffff); while (nShift < 29) { dDiff *= 256.0; nShift++; } while (nShift > 29) { dDiff /= 256.0; nShift--; } return(dDiff); }