<p>To explain that, let's look at the code that unpacks the compact format into a 256 bit int.</p>

<pre><code>arith_uint256&amp; arith_uint256::SetCompact(uint32_t nCompact, bool* pfNegative, bool* pfOverflow)
{
    int nSize = nCompact &gt;&gt; 24;
    uint32_t nWord = nCompact &amp; 0x007fffff;
    if (nSize &lt;= 3) {
        nWord &gt;&gt;= 8 * (3 - nSize);
        *this = nWord;
    } else {
        *this = nWord;
        *this &lt;&lt;= 8 * (nSize - 3);
    }
    if (pfNegative)
        *pfNegative = nWord != 0 &amp;&amp; (nCompact &amp; 0x00800000) != 0;
    if (pfOverflow)
        *pfOverflow = nWord != 0 &amp;&amp; ((nSize &gt; 34) ||
                                     (nWord &gt; 0xff &amp;&amp; nSize &gt; 33) ||
                                     (nWord &gt; 0xffff &amp;&amp; nSize &gt; 32));
    return *this;
}
</code></pre>

<p>The first 8 bits here are the exponent. The next bit is a sign bit, with 1 being negative. The next 23 bits are the mantissa.</p>

<p>So, <code>0x00800000</code> is equal to <code>0x00000000</code>.</p>

CC BY-SA 3.0
2016-09-22T12:03:25.787Z
Yes `0x00800000` is equal to `0x00000000`, but I think the wiki is referring to the part after the Bits removed the first byte, and it says `0x008000` instead of `0x800000` is the smallest positive valid value.
hello.wjx
CC BY-SA 3.0
2016-09-22T17:57:57.517Z
0x008000 is also equal to zero, because it is right shifted three times. For that matter, 0x01008000 would equal zero too.
Nick ODell
CC BY-SA 3.0
2016-09-23T15:08:57.550Z
Then 0x007000, 0x006000 ... all equal to zero, and all are smaller than 0x008000
hello.wjx
CC BY-SA 3.0
2016-09-22T04:58:18.340Z
2016-09-22T04:58:18.340Z
Nick ODell
<p>The <a href="https://en.bitcoin.it/wiki/Difficulty" rel="nofollow noreferrer">bitcoin wiki</a> describes difficulty target representation as follows:</p>
<blockquote>
<p>How is difficulty stored in blocks? Each block stores a packed
representation (called &quot;Bits&quot;) for its actual hexadecimal target. The
target can be derived from it via a predefined formula. For example,
if the packed target in the block is 0x1b0404cb, the hexadecimal
target is</p>
<p>0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000</p>
<p>Note that the 0x0404cb value is a signed value in this format. The
largest legal value for this field is 0x7fffff. To make a larger value
you must shift it down one full byte. Also 0x008000 is the smallest
positive valid value.</p>
</blockquote>
<p>Why <code>0x008000</code> is the smallest positive valid value?</p>

<difficulty>
Difficulty target representation in bitcoin wiki
hello.wjx
# Difficulty target representation in bitcoin wiki

(Asked by: username_0 on 2016-09-21)

The [bitcoin wiki](https://en.bitcoin.it/wiki/Difficulty) describes difficulty target representation as follows:

> How is difficulty stored in blocks? Each block stores a packed
> representation (called "Bits") for its actual hexadecimal target. The
> target can be derived from it via a predefined formula. For example,
> if the packed target in the block is 0x1b0404cb, the hexadecimal
> target is
>
> 0x0404cb \* 2\*\*(8\*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000
>
> Note that the 0x0404cb value is a signed value in this format. The
> largest legal value for this field is 0x7fffff. To make a larger value
> you must shift it down one full byte. Also 0x008000 is the smallest
> positive valid value.

Why `0x008000` is the smallest positive valid value?

**Tags:** difficulty


---

## 1 answers

### Answer by username_1 on 2016-09-22. Score: 2

To explain that, let's look at the code that unpacks the compact format into a 256 bit int.
arith_uint256& arith_uint256::SetCompact(uint32_t nCompact, bool* pfNegative, bool* pfOverflow)
{
    int nSize = nCompact >> 24;
    uint32_t nWord = nCompact & 0x007fffff;
    if (nSize <= 3) {
        nWord >>= 8 * (3 - nSize);
        *this = nWord;
    } else {
        *this = nWord;
        *this <<= 8 * (nSize - 3);
    }
    if (pfNegative)
        *pfNegative = nWord != 0 && (nCompact & 0x00800000) != 0;
    if (pfOverflow)
        *pfOverflow = nWord != 0 && ((nSize > 34) ||
                                     (nWord > 0xff && nSize > 33) ||
                                     (nWord > 0xffff && nSize > 32));
    return *this;
}

The first 8 bits here are the exponent. The next bit is a sign bit, with 1 being negative. The next 23 bits are the mantissa.
So, 0x00800000 is equal to 0x00000000.

> **Comments:**
> **username_0**: Yes `0x00800000` is equal to `0x00000000`, but I think the wiki is referring to the part after the Bits removed the first byte, and it says `0x008000` instead of `0x800000` is the smallest positive valid value.  
> **username_1**: 0x008000 is also equal to zero, because it is right shifted three times. For that matter, 0x01008000 would equal zero too.  
> **username_0**: Then 0x007000, 0x006000 ... all equal to zero, and all are smaller than 0x008000  

---

