Decimal to binary conversion without using arithmetic operators | function for decimal to binary conversion without using arithmetic operators ; to store the binary equivalent of decimal ; to get the last binary digit of the number ' n ' and accumulate it at the beginning of ' bin ' ; right shift ' n ' by 1 ; required binary number ; Driver program to test above
function decToBin ( n ) { if ( n == 0 ) return " " ; var bin = " " ; while ( n > 0 ) { bin = ( ( n & 1 ) == 0 ? ' ' : ' ' ) + bin ; n >>= 1 ; } return bin ; } var n = 38 ; document . write ( decToBin ( n ) ) ;