MCPcopy Index your code
hub / github.com/petertodd/python-bitcoinlib / uint256_from_compact

Function uint256_from_compact

bitcoin/core/serialize.py:306–316  ·  view source on GitHub ↗

Convert compact encoding to uint256 Used for the nBits compact encoding of the target in the block header.

(c)

Source from the content-addressed store, hash-verified

304
305
306def uint256_from_compact(c):
307 """Convert compact encoding to uint256
308
309 Used for the nBits compact encoding of the target in the block header.
310 """
311 nbytes = (c >> 24) & 0xFF
312 if nbytes <= 3:
313 v = (c & 0xFFFFFF) >> 8 * (3 - nbytes)
314 else:
315 v = (c & 0xFFFFFF) << (8 * (nbytes - 3))
316 return v
317
318def compact_from_uint256(v):
319 """Convert uint256 to compact encoding

Callers 3

CheckProofOfWorkFunction · 0.85
test_twelveMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_twelveMethod · 0.68