Find i 'th Index character in a binary string obtained after n iterations | C # Program to find ith character in a binary string . ; Function to store binary Representation ; Function to find ith character ; Function to change decimal to binary ; Assign s1 string in s string ; Driver Code
using System ; class GFG { static string ReverseString ( string s ) { char [ ] arr = s . ToCharArray ( ) ; Array . Reverse ( arr ) ; return new string ( arr ) ; } static void binary_conversion ( ref string s , int m ) { while ( m != 0 ) { int tmp = m % 2 ; s += tmp . ToString ( ) ; m = ( int ) ( m / 2 ) ; } s = ReverseString ( s ) ; } static int find_character ( int n , int m , int i ) { string s = " " ; binary_conversion ( ref s , m ) ; string s1 = " " ; for ( int x = 0 ; x < n ; x ++ ) { for ( int y = 0 ; y < s . Length ; y ++ ) { if ( s [ y ] == '1' ) s1 += "10" ; else s1 += "01" ; } s = s1 ; s1 = " " ; } return s [ i ] - '0' ; } static void Main ( ) { int m = 5 , n = 2 , i = 8 ; Console . Write ( find_character ( n , m , i ) ) ; } }