Powers of 2 to required sum | Python3 program to find the blocks for given number . ; Converting the decimal number into its binary equivalent . ; Displaying the output when the bit is '1' in binary equivalent of number . ; Driver Code
def block ( x ) : NEW_LINE INDENT v = [ ] NEW_LINE print ( " Blocks ▁ for ▁ % d ▁ : ▁ " % x , end = " " ) NEW_LINE while ( x > 0 ) : NEW_LINE INDENT v . append ( int ( x % 2 ) ) NEW_LINE x = int ( x / 2 ) NEW_LINE DEDENT for i in range ( 0 , len ( v ) ) : NEW_LINE INDENT if ( v [ i ] == 1 ) : NEW_LINE INDENT print ( i , end = " " ) NEW_LINE if ( i != len ( v ) - 1 ) : NEW_LINE INDENT print ( " , ▁ " , end = " " ) NEW_LINE DEDENT DEDENT DEDENT print ( " " ) NEW_LINE DEDENT block ( 71307 ) NEW_LINE block ( 1213 ) NEW_LINE block ( 29 ) NEW_LINE block ( 100 ) NEW_LINE