Decimal to octal conversion with minimum use of arithmetic operators | C # implementation of 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 Code
using System ; using System . Collections . Generic ; class GFG { static string decToBin ( int n ) { if ( n == 0 ) return "0" ; string bin = " " ; while ( n > 0 ) { bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ; n >>= 1 ; } return bin ; } static string convertBinToOct ( string bin ) { int l = bin . Length ; for ( int j = 1 ; j <= ( 3 - l % 3 ) % 3 ; j ++ ) bin = '0' + bin ; Dictionary < string , char > bin_oct_map = new Dictionary < string , char > ( ) ; bin_oct_map . Add ( "000" , '0' ) ; bin_oct_map . Add ( "001" , '1' ) ; bin_oct_map . Add ( "010" , '2' ) ; bin_oct_map . Add ( "011" , '3' ) ; bin_oct_map . Add ( "100" , '4' ) ; bin_oct_map . Add ( "101" , '5' ) ; bin_oct_map . Add ( "110" , '6' ) ; bin_oct_map . Add ( "111" , '7' ) ; int i = 0 ; string octal = " " ; while ( true ) { octal += bin_oct_map [ bin . Substring ( i , 3 ) ] ; i += 3 ; if ( i == bin . Length ) break ; } return octal ; } static string decToOctal ( int n ) { string bin = decToBin ( n ) ; return convertBinToOct ( bin ) ; } public static void Main ( string [ ] args ) { int n = 151 ; Console . Write ( decToOctal ( n ) ) ; } }