## Description

CompactToBig converts a compact representation of a whole number N to an unsigned 32-bit number. The representation is similar to IEEE754 floating point numbers.

Like IEEE754 floating point, there are three basic components: the sign, the exponent, and the mantissa. They are broken out as follows:

* the most significant 8 bits represent the unsigned base 256 exponent * bit 23 (the 24th bit) represents the sign bit * the least significant 23 bits represent the mantissa ------------------------------------------------- | Exponent | Sign | Mantissa | ------------------------------------------------- | 8 bits [31-24] | 1 bit [23] | 23 bits [22-00] | -------------------------------------------------

The formula to calculate N is:

N = (-1^sign) * mantissa * 256^(exponent-3)

This compact form is only used in bitcoin to encode unsigned 256-bit numbers which represent difficulty targets, thus there really is not a need for a sign bit, but it is implemented here to stay consistent with bitcoind.

## Examples

// Create a couple of convenience variables. header := &msgBlock.Header targetDifficulty := blockchain.CompactToBig(header.Bits) // Initial state.

"fees, %d signature operations, %d bytes, target difficulty "+ "%064x)", len(msgBlock.Transactions), totalFees, blockSigOps, blockSize, blockchain.CompactToBig(msgBlock.Header.Bits)) return &BlockTemplate{

// work limit directly because the block difficulty is encoded in a block // with the compact form which loses precision. max := blockchain.CompactToBig(activeNetParams.PowLimitBits) target := blockchain.CompactToBig(bits)

## CompactToBig is referenced in 3 repositories

**github.com/btcsuite/btcd**

- 8 references in rpcserver.go
- 4 references in blockchain/difficulty.go
- 2 references in blockchain/process.go
- 1 reference in blockchain/difficulty_test.go
- 1 reference in blockchain/example_test.go

**github.com/OpenBazaar/spvwallet**

- 3 references in blockchain.go
- 2 references in header.go

...