<p>If you convert the difficulty bits to hex you will get:
<code>0x1F00FFFF</code></p>

<p>Coefficient = <code>0x00FFFF</code></p>

<p>Exponent = <code>1F = 31</code></p>

<p>Target = <code>Coefficient * 2**( 8 * ( exponent-3 ) )</code></p>

<p>Target = <code>0xFFFF</code> with <code>31 - 3 = 28</code> trailing NULL (<code>0x00</code>) bytes</p>

<p>Target:
<code>0x0000FFFF00000000000000000000000000000000000000000000000000000000</code></p>

<p>Your Hash:
<code>0x000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1</code></p>

<p>So your POW fulfils the target.
Just to be sure, you might want to check endianness during your conversions between int/literal/hex types.</p>

CC BY-SA 4.0
2018-12-11T13:41:54.520Z
2018-12-12T06:43:02.403Z
2018-12-12T06:43:02.403Z
James C.
<p>I am currently trying to validate a blocks hash against its target in python3:</p>

<p>This is a <a href="https://api.blockcypher.com/v1/bcy/test/blocks/000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1" rel="nofollow noreferrer">block</a> in the Blockcypher testnet, and I am using this <a href="https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_stored_in_blocks.3F" rel="nofollow noreferrer">formula</a> from the Bitcoin Wiki.</p>

<pre><code>block_hash = '000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1'
bits = '520159231'

target = hex(int(bits) * (2**(8 * (0x1b - 3))))
hash_ = hex(int(block_hash, 16))
print(target, hash_)
&gt;&gt;&gt; 0x1f00ffff000000000000000000000000000000000000000000000000 0x55f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1

if not target &gt;= hash_:
    print('False)
else:
    print('True')
&gt;&gt;&gt; False
</code></pre>

<p>Point is, that target is less than blockhash. But this should not be the case.
<strong>Can anyone help me?</strong></p>

<p>Thank You for Your time.</p>

CC BY-SA 4.0
2018-12-11T14:46:21.030Z
That's because that target is represented in compact format: https://bitcoin.org/en/developer-reference#target-nbits
JBaczuk
<hash><difficulty><python>
Why is Target < Blockhash?
SimonSchuler
# Why is Target < Blockhash?

(Asked by: username_0 on 2018-12-11)

I am currently trying to validate a blocks hash against its target in python3:

This is a [block](https://api.blockcypher.com/v1/bcy/test/blocks/000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1) in the Blockcypher testnet, and I am using this [formula](https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_stored_in_blocks.3F) from the Bitcoin Wiki.

```
block_hash = '000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1'
bits = '520159231'

target = hex(int(bits) * (2**(8 * (0x1b - 3))))
hash_ = hex(int(block_hash, 16))
print(target, hash_)
>>> 0x1f00ffff000000000000000000000000000000000000000000000000 0x55f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1

if not target >= hash_:
    print('False)
else:
    print('True')
>>> False

```

Point is, that target is less than blockhash. But this should not be the case.
**Can anyone help me?**

Thank You for Your time.

**Tags:** hash, difficulty, python

> **Comments:**
> **username_1**: That's because that target is represented in compact format: https://bitcoin.org/en/developer-reference#target-nbits  

---

## 1 answers

### Answer by username_2 on 2018-12-11. Score: 5 | Accepted answer

If you convert the difficulty bits to hex you will get:
`0x1F00FFFF`

Coefficient = `0x00FFFF`

Exponent = `1F = 31`

Target = `Coefficient * 2**( 8 * ( exponent-3 ) )`

Target = `0xFFFF` with `31 - 3 = 28` trailing NULL (`0x00`) bytes

Target:
`0x0000FFFF00000000000000000000000000000000000000000000000000000000`

Your Hash:
`0x000055f67563d1c2cb141d06d52d2fca63ef457c553519aeb635a2643a9af0b1`

So your POW fulfils the target.
Just to be sure, you might want to check endianness during your conversions between int/literal/hex types.


---

