Decimal to octal conversion with minimum use of 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 ; Function to find octal equivalent of binary ; add min 0 's in the beginning to make  string length divisible by 3 ; create map between binary and its equivalent octal code ; one by one extract from left , substring of size 3 and add its octal code ; required octal number ; function to find octal equivalent of decimal ; convert decimal to binary ; convert binary to octal required octal equivalent of decimal ; 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 ; } function convertBinToOct ( bin ) { var l = bin . length ; for ( var i = 1 ; i <= ( 3 - l % 3 ) % 3 ; i ++ ) bin = ' ' + bin ; var bin_oct_map = new Map ( ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; bin_oct_map . set ( " " , ' ' ) ; var i = 0 ; var octal = " " ; while ( 1 ) { octal += bin_oct_map . get ( bin . substring ( i , i + 3 ) ) ; i += 3 ; if ( i == bin . length ) break ; } return octal ; } function decToOctal ( n ) { var bin = decToBin ( n ) ; return convertBinToOct ( bin ) ; } var n = 151 ; document . write ( decToOctal ( n ) ) ; ing