Author

Topic: How to get <target> values ​​for a block? The question is closed. (Read 67 times)

newbie
Activity: 24
Merit: 2
You provided nbits = 422681968
If you convert that integer value to hex, you get the 4 bytes (32 bits) that nbits is made up of:
422681968 = hex value 0x19319D70

Split the first byte off of nbits to get hex value 0x19 leaving behind the remaining 3 bytes of 0x319D70
These are the two pieces that are used to calculate the target hash value and the difficulty using this formula:
TARGET = 0x319D70 * 2(8(0x19 - 3))

To make the math a bit easier to understand, we can convert those hex values back to integers for the purposes of this discussion:
= 3251568 * 2(8(25-3))
= 3251568 * 2(8(22))
= 3251568 * 2176
= 3251568 * 95780971304118053647396689196894323976171195136475136
TARGET = 311438341301388531462158357898567283222551020627518185013248

Convert this value back to hex to get the hash value that the block hash is compared to:
TARGET = 0x00000000000000319d7000000000000000000000000000000000000000000000

You may notice that hex value of TARGET is 0x319D70 shifted to the left until the 31 is in the 25'th (0x19) byte from the right. That's what that formula above does. It takes the last 3 bytes (6 characters) from nbits, and shifts them to the left until the first byte of that block of 3 bytes is exactly the number of bytes from the right that is specified by the first byte of nbits.

Now that you have the TARGET, the DIFFICULTY is just:
DIFFICULTY = (0xffff * 2208)/TARGET

Let's convert the formula above into integers to make the math easier to follow:
(65535 * 2208)/TARGET

We have the integer value of TARGET above so:
(65535 * 2208)/311438341301388531462158357898567283222551020627518185013248
= 86564599.52 = DIFFICULTY

Regarding my most recent message to you...

You didn't ask for it, but it's the calculation of the expected hash rate for a given difficulty is closely related, so I figured I'd share it.

The average number of hashes needed to find an acceptable hash at a given difficulty can be calculated as:
DIFFICULTY * 2256 / (0xffff * 2208)

Since the difficulty on the previous example was:
86564599.52

The average number of hashes that need to be calculated per block is:
= 86564599.52 * 2256 / (0xffff * 2208)
= 86564599.52 * 2256 / (65535 * 2208)
= 371797797113897361

Since blocks are intended to occur on average every 10 minutes (and there are 600 seconds in 10 minutes), this means that a difficulty of 86564599.52 would be set when the global average hash rate is:
371797797113897361 total hashes / 600 seconds = 619662995189828 hashes per second.

That's about 619.663 Thash/sec

The question is closed.
Jump to: