<blockquote>
  <p>I'm struggling to find a way to calculate the bitcoin equivalent “target” from that number.</p>
</blockquote>

<p>Your difficulty recalculation algorithm will need to be completely different then. The easiest way to change it is to just start with an initial difficulty with all bits set and then bit shift this number as needed to get a target with some set number of leading zeros.</p>

<blockquote>
  <p>Additionally I wonder why it is not implemented that way in the bitcoin protocol? Does it cause too harsh steps of difficulty?</p>
</blockquote>

<p>Because it only allows for the difficulty to double or halve. Furthermore, there are only 256 possible difficulties so this is not at all ideal nor would it work particularly well. This means that the target would usually be too high or too low. By using a target value, the difficulty can be adjusted to far more levels (2^256 possible difficulties) to better match the network hashrate.</p>

CC BY-SA 3.0
2018-03-21T20:01:15.800Z
2018-03-21T20:01:15.800Z
Ava Chow
<p>I'm implementing my own cryptocurrency and I found it that saving the "hash difficulty” as the leading off (<code>0</code>) bits of a 256 bit number in a SHA-256 hash is the most intuitive.</p>

<p>I'm struggling to find a way to calculate the bitcoin equivalent “target” from that number.</p>

<p>Additionally I wonder why it is not implemented that way in the bitcoin protocol? Does it cause too harsh steps of difficulty?</p>

<mining-theory><difficulty>
Calculating the target from the hash leading off bits
downrep_nation
# Calculating the target from the hash leading off bits

(Asked by: username_0 on 2018-03-21)

I'm implementing my own cryptocurrency and I found it that saving the "hash difficulty” as the leading off (`0`) bits of a 256 bit number in a SHA-256 hash is the most intuitive.

I'm struggling to find a way to calculate the bitcoin equivalent “target” from that number.

Additionally I wonder why it is not implemented that way in the bitcoin protocol? Does it cause too harsh steps of difficulty?

**Tags:** mining-theory, difficulty


---

## 1 answers

### Answer by username_1 on 2018-03-21. Score: 2 | Accepted answer

> I'm struggling to find a way to calculate the bitcoin equivalent “target” from that number.

Your difficulty recalculation algorithm will need to be completely different then. The easiest way to change it is to just start with an initial difficulty with all bits set and then bit shift this number as needed to get a target with some set number of leading zeros.

> Additionally I wonder why it is not implemented that way in the bitcoin protocol? Does it cause too harsh steps of difficulty?

Because it only allows for the difficulty to double or halve. Furthermore, there are only 256 possible difficulties so this is not at all ideal nor would it work particularly well. This means that the target would usually be too high or too low. By using a target value, the difficulty can be adjusted to far more levels (2^256 possible difficulties) to better match the network hashrate.


---

