If you thought grep was powerful, wait until you get a hold of ast-grep, which takes it to a whole new level.
Assume the integer is 32 bit. XOR a and b, shift by 1 bit everytime -> want to check the XORed value at index 0 : just & 1 will do. Count the above calculated result: how many bit difference do a and ...