I'm looking to compare bits of a hash in Python3, as part of a Hashcash system. So for instance, I want to know if the first N bits of a SHA256 hash are 0.
Right now, I'm doing this based on the hex version
if newhash.hexdigest()[0:4] == '0000'
But this doesn't let me be as granular as I want - I'd prefer to compare the raw bits, which lets me vary the number of matching 0s far more closely.
I get get the bit values to compare through a convoluted hop
bin(int(h.hexdigest(), 16))[2:]
but this seems like it can't possibly be the fastest/right way to do it.
I'd appreciate any advise on the right/correct way to do it ;)
Thanks,
-CPD