Convert compact encoding to uint256 Used for the nBits compact encoding of the target in the block header.
(c)
| 304 | |
| 305 | |
| 306 | def 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 | |
| 318 | def compact_from_uint256(v): |
| 319 | """Convert uint256 to compact encoding |
no outgoing calls