[#arith_uint256-SetCompact]
= xref:arith_uint256.adoc[arith&lowbar;uint256]::SetCompact
:relfileprefix: ../
:mrdocs:

The &quot;compact&quot; format is a representation of a whole number N using an unsigned 32bit number similar to a floating point format&period; The most significant 8 bits are the unsigned exponent of base 256&period; This exponent can be thought of as &quot;number of bytes of N&quot;&period; The lower 23 bits are the mantissa&period; Bit number 24 (0x800000) represents the sign of N&period; N &equals; (&hyphen;1&circ;sign) &ast; mantissa &ast; 256&circ;(exponent&hyphen;3)

== Synopsis

Declared in `&lt;arith&lowbar;uint256&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:arith_uint256.adoc[arith&lowbar;uint256]&
SetCompact(
    uint32&lowbar;t nCompact,
    bool* pfNegative = nullptr,
    bool* pfOverflow = nullptr);
----

== Description

Satoshi&apos;s original implementation used BN&lowbar;bn2mpi() and BN&lowbar;mpi2bn()&period; MPI uses the most significant bit of the first byte as sign&period; Thus 0x1234560000 is compact (0x05123456) and 0xc0de000000 is compact (0x0600c0de)

Bitcoin only uses this &quot;compact&quot; format for encoding difficulty targets, which are unsigned 256bit quantities&period; Thus, all the complexities of the sign bit and using base 256 are probably an implementation accident&period;

Decodes a value from the compact difficulty&hyphen;target format described above&period;

== Return Value

A reference to this object holding the decoded value&period;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *nCompact*
| The 32&hyphen;bit compact encoding to decode&period;
| *pfNegative*
| If not null, set to true when the encoded sign bit is set&period;
| *pfOverflow*
| If not null, set to true when the encoded value overflows 256 bits&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
