Position of rightmost bit with first carry in sum of two binary | Python3 implementation to find the position of rightmost bit where a carry is generated first ; function to find the position of rightmost set bit in 'n ; function to find the position of rightmost bit where a carry is generated first ; Driver program to test above
import math NEW_LINE ' NEW_LINE def posOfRightmostSetBit ( n ) : NEW_LINE INDENT return int ( math . log2 ( n & - n ) + 1 ) NEW_LINE DEDENT def posOfCarryBit ( a , b ) : NEW_LINE INDENT return posOfRightmostSetBit ( a & b ) NEW_LINE DEDENT a = 10 NEW_LINE b = 2 NEW_LINE print ( posOfCarryBit ( a , b ) ) NEW_LINE