Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: wingding on April 17, 2014, 05:49:15 PM



Title: How is target and difficulty related?
Post by: wingding on April 17, 2014, 05:49:15 PM
As I understand, the difficulty is the number of hashes, divided by 2^32, required (in average) in order to get a SHA-256 below a target value T. And further, that the target value is actually what is adjusted in the algorithm. Is it then correct that D*(2^32)=(2^256)/T ? Or have I got it wrong here?


Title: Re: How is target and difficulty related?
Post by: Shogen on April 19, 2014, 12:48:11 PM
You can find the info in details in the wiki.
For your reference: https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F


Title: Re: How is target and difficulty related?
Post by: Remember remember the 5th of November on April 19, 2014, 08:24:09 PM
The difficulty is a human-readable representation of the target, just for us to be more comfortable with it.


Title: Re: How is target and difficulty related?
Post by: Nicolas Dorier on April 20, 2014, 12:33:13 AM
I implemented that code yestersday.
https://github.com/NicolasDorier/NBitcoin/blob/master/NBitcoin/Target.cs

You will find some test sample at
https://github.com/NicolasDorier/NBitcoin/blob/master/NBitcoin.Tests/util_tests.cs
In the test CanReadConvertTargetToDifficulty

This take Target from differelsnt form (packed and unpacked) and calculate difficulty from it.