Guest User

Untitled

a guest
Jan 23rd, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. uint256& uint256::SetCompact(uint32_t nCompact, bool *pfNegative, bool *pfOverflow)
  2. {
  3. int nSize = nCompact >> 24;
  4. uint32_t nWord = nCompact & 0x007fffff;
  5. if (nSize <= 3) {
  6. nWord >>= 8*(3-nSize);
  7. *this = nWord;
  8. } else {
  9. *this = nWord;
  10. *this <<= 8*(nSize-3);
  11. }
  12. if (pfNegative)
  13. *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
  14. if (pfOverflow)
  15. *pfOverflow = nWord != 0 && ((nSize > 34) ||
  16. (nWord > 0xff && nSize > 33) ||
  17. (nWord > 0xffff && nSize > 32));
  18. return *this;
  19. }
  20.  
  21. uint32_t uint256::GetCompact(bool fNegative) const
  22. {
  23. int nSize = (bits() + 7) / 8;
  24. uint32_t nCompact = 0;
  25. if (nSize <= 3) {
  26. nCompact = GetLow64() << 8*(3-nSize);
  27. } else {
  28. uint256 bn = *this >> 8*(nSize-3);
  29. nCompact = bn.GetLow64();
  30. }
  31. // The 0x00800000 bit denotes the sign.
  32. // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
  33. if (nCompact & 0x00800000) {
  34. nCompact >>= 8;
  35. nSize++;
  36. }
  37. assert((nCompact & ~0x007fffff) == 0);
  38. assert(nSize < 256);
  39. nCompact |= nSize << 24;
  40. nCompact |= (fNegative && (nCompact & 0x007fffff) ? 0x00800000 : 0);
  41. return nCompact;
  42. }
  43.  
  44. #!/bin/bash
  45. echo "ibase=16;FFFF0000000000000000000000000000000000000000000000000000 / $1" | bc -l
  46.  
  47. $ ./target-to-difficulty.sh 000000000000000024DBE9000000000000000000000000000000000000000000
  48. 29829733124.04041574884510759883
Add Comment
Please, Sign In to add comment