# （转）比特币的挖矿的难度

0x0404cb * 2^(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000

0x00000000FFFF0000000000000000000000000000000000000000000000000000 /
0x00000000000404CB000000000000000000000000000000000000000000000000
= 16307.420938523983 (bdiff)

0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /
0x00000000000404CB000000000000000000000000000000000000000000000000
= 16307.669773817162 (pdiff)

#include <iostream>
#include <cmath>
inline float fast_log(float val)
{
int * const exp_ptr = reinterpret_cast <int *>(&val);
int x = *exp_ptr;
const int log_2 = ((x >> 23) & 255) – 128;
x &= ~(255 << 23);
x += 127 << 23;
*exp_ptr = x;
val = ((-1.0f/3) * val + 2) * val – 2.0f/3;
return ((val + log_2) * 0.69314718f);
}

float difficulty(unsigned int bits)
{
static double max_body = fast_log(0x00ffff), scaland = fast_log(256);
return exp(max_body – fast_log(bits & 0x00ffffff) + scaland * (0x1d – ((bits & 0xff000000) >> 24)));

}
int main()
{
std::cout << difficulty(0x1b0404cb) << std::endl;
return 0;
}

import decimal, math
l = math.log
e = math.e

print 0x00ffff * 2**(8*(0x1d3)) / float(0x0404cb * 2**(8*(0x1b3)))

print l(0x00ffff * 2**(8*(0x1d3)) / float(0x0404cb * 2**(8*(0x1b3))))

print l(0x00ffff * 2**(8*(0x1d3))) – l(0x0404cb * 2**(8*(0x1b3)))

print l(0x00ffff) + l(2**(8*(0x1d3))) – l(0x0404cb) – l(2**(8*(0x1b3)))

print l(0x00ffff) + (8*(0x1d3))*l(2) – l(0x0404cb) – (8*(0x1b3))*l(2)

print l(0x00ffff / float(0x0404cb)) + (8*(0x1d3))*l(2) – (8*(0x1b3))*l(2)

print l(0x00ffff / float(0x0404cb)) + (0x1d0x1b)*l(2**8)

0xffff * 2^208

(0xffff * 2^208)/D

D * 2^256 / (0xffff * 2^208)

D * 2^48 / 0xffff

D * 2^48 / 0xffff / 600

D * 2^32 / 600

5,006,860,589 * 2^32 / 600 = 大约在35.840 PHash/s

\$ python -c “print 20000 * 2**32 / 10**9 / 60 / 60.0”
23.85