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 Code
< ? php function decToBin ( $ n ) { if ( $ n == 0 ) return "0" ; $ bin = " " ; while ( $ n > 0 ) { $ bin = ( ( $ n & 1 ) == 0 ? '0' : '1' ) . $ bin ; $ n >>= 1 ; } return $ bin ; } $ n = 38 ; echo decToBin ( $ n ) ; ? >