Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint256& uint256::SetCompact(uint32_t nCompact, bool *pfNegative, bool *pfOverflow)
- {
- int nSize = nCompact >> 24;
- uint32_t nWord = nCompact & 0x007fffff;
- if (nSize <= 3) {
- nWord >>= 8*(3-nSize);
- *this = nWord;
- } else {
- *this = nWord;
- *this <<= 8*(nSize-3);
- }
- if (pfNegative)
- *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
- if (pfOverflow)
- *pfOverflow = nWord != 0 && ((nSize > 34) ||
- (nWord > 0xff && nSize > 33) ||
- (nWord > 0xffff && nSize > 32));
- return *this;
- }
- uint32_t uint256::GetCompact(bool fNegative) const
- {
- int nSize = (bits() + 7) / 8;
- uint32_t nCompact = 0;
- if (nSize <= 3) {
- nCompact = GetLow64() << 8*(3-nSize);
- } else {
- uint256 bn = *this >> 8*(nSize-3);
- nCompact = bn.GetLow64();
- }
- // The 0x00800000 bit denotes the sign.
- // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
- if (nCompact & 0x00800000) {
- nCompact >>= 8;
- nSize++;
- }
- assert((nCompact & ~0x007fffff) == 0);
- assert(nSize < 256);
- nCompact |= nSize << 24;
- nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
- return nCompact;
- }
- #!/bin/bash
- echo "ibase=16;FFFF0000000000000000000000000000000000000000000000000000 / $1" | bc -l
- $ ./target-to-difficulty.sh 000000000000000024DBE9000000000000000000000000000000000000000000
- 29829733124.04041574884510759883
Add Comment
Please, Sign In to add comment