How to calculate difficulty from Bits fields (which is stored in block).
- Convert value to hex:
bits=471067731 -> 0x1c13ec53
- Split hex value, take 8 high bits (
0x1c
), and 24 low (0x13ec53
)
- Use formula to get 256-bit target value:
T = low * 2 ^ (8 * (high - 3))
. In our case it will be: T = 0x13ec53 * 2 ^ (8 * (0x1c - 3)) = 0x0000000013ec5300000000000000000000000000000000000000000000000000
- Divide highest possible target Tmax (
0x00000000ffff0000000000000000000000000000000000000000000000000000
) by our T. If we truncate zeros, it will be: 0x13ec53 / 0xffff00 = 12.849
Network recalculates difficulty every 2016 blocks (2 weeks). This is how 12.85 is getting recalculated from block timestamps:
block - diff - time stamp
...
52415 - 7.82 (2010-04-21 21:50:53)
52416 - 11.46 (2010-04-21 21:52:52) <- difficulty update
...
54430 - 11.46 (2010-05-04 09:39:19)
54431 - 11.46 (2010-05-04 09:40:03)
54432 - 12.85 (2010-05-04 09:46:16) <- difficulty update
...
55798 - 12.85 (2010-05-14 16:21:05) <- your block
When network recalculates difficulty, it takes time to mine the latest 2015 blocks (due to bug in code, it should take 2016). In our example, it would be:
2010-05-04 09:40:03 - 2010-04-21 21:52:52 = 12.491 days
In normal scenario 2016 block should be mined in 14 days. So, new difficulty:
11.46 * 14 / 12.491 = 12.844