Powers of 2 to required sum | Javascript program to find the blocks for given number . ; Convert decimal number to its binary equivalent ; Displaying the output when the bit is '1' in binary equivalent of number . ; Driver code
function block ( x ) { let v = [ ] ; document . write ( " " + x + " " ) ; while ( x > 0 ) { v . push ( x % 2 ) ; x = parseInt ( x / 2 , 10 ) ; } for ( let i = 0 ; i < v . length ; i ++ ) { if ( v [ i ] == 1 ) { document . write ( i ) ; if ( i != v . length - 1 ) document . write ( " " ) ; } } document . write ( " " ) ; } block ( 71307 ) ; block ( 1213 ) ; block ( 29 ) ; block ( 100 ) ;