def uint256_from_compact(c):
    """Convert compact encoding to uint256

    Used for the nBits compact encoding of the target in the block header.
    """
    nbytes = c >> 24 & 255
    if nbytes <= 3:
        v = (c & 16777215) >> 8 * (3 - nbytes)
    else:
        v = (c & 16777215) << 8 * (nbytes - 3)
    return v
