codeparrot/xlcost-text-to-code huggingface dataset:
Maximum subset with bitwise OR equal to k | C # Program to find the maximum subset with bitwise OR equal to k ; function to find the maximum subset with bitwise OR equal to k ; If the bitwise OR of k and element is equal to k , then include that element in the subset ; Store the bitwise OR of elements in v ; If ans is not equal to k , subset doesn 't exist ; main function
using System ; using System . Collections ; class GFG { static void subsetBitwiseORk ( int [ ] arr , int n , int k ) { ArrayList v = new ArrayList ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] k ) == k ) { v . Add ( arr [ i ] ) ; } } int ans = 0 ; for ( int i = 0 ; i < v . Count ; i ++ ) ans = ans | ( int ) v [ i ] ; if ( ans != k ) { Console . WriteLine ( " Subset ▁ does " + " ▁ not ▁ exist " ) ; return ; } for ( int i = 0 ; i < v . Count ; i ++ ) Console . Write ( ( int ) v [ i ] + " ▁ " ) ; } static public void Main ( String [ ] args ) { int k = 3 ; int [ ] arr = { 1 , 4 , 2 } ; int n = arr . Length ; subsetBitwiseORk ( arr , n , k ) ; } }
Number whose XOR sum with given array is a given number k | C # Program to find the number whose XOR sum with given array is equal to a given number k ; This function returns the number to be inserted in the given array ; initialise the answer with k ; XOR of all elements in the array ; Driver Code to test above function
using System ; class GFG { static int findEletobeInserted ( int [ ] A , int n , int k ) { int ans = k ; for ( int i = 0 ; i < n ; i ++ ) ans ^= A [ i ] ; return ans ; } public static void Main ( ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; int n = A . Length ; int k = 10 ; Console . WriteLine ( findEletobeInserted ( A , n , k ) + " ▁ has ▁ to ▁ be ▁ inserted ▁ in ▁ " + " the ▁ given ▁ array ▁ to ▁ make " + " ▁ xor ▁ sum ▁ of ▁ " + k ) ; } }
Range query for count of set bits | C # program to Range query for Count number of set bits ; 2 - D array that will stored the count of bits set in element of array ; Function store the set bit count in BitCount Array ; traverse over all bits ; mark elements with i 'th bit set ; Check whether the current bit is set or not if it 's  set then mark it. ; store cumulative sum of bits ; Function to process queries ; Driver Code
using System ; class GFG { static int [ ] BitCount = new int [ 10000 ] ; static void fillSetBitsMatrix ( int [ ] arr , int n ) { for ( int i = 0 ; i < 32 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { long temp = arr [ j ] >> i ; if ( temp % 2 != 0 ) BitCount [ j ] += 1 ; } } for ( int i = 1 ; i < n ; i ++ ) BitCount [ i ] += BitCount [ i - 1 ] ; } static void Query ( int [ , ] Q , int q ) { for ( int i = 0 ; i < q ; i ++ ) Console . WriteLine ( ( BitCount [ Q [ i , 1 ] ] - BitCount [ Q [ i , 0 ] - 1 ] ) ) ; } public static void Main ( ) { int [ ] Arr = { 1 , 5 , 6 , 10 , 9 , 4 , 67 } ; int n = Arr . Length ; fillSetBitsMatrix ( Arr , n ) ; int q = 2 ; int [ , ] Q = { { 1 , 5 } , { 2 , 6 } } ; Query ( Q , q ) ; } }
Generate n | C # program to generate n - bit gray codes ; Function to convert decimal to binary ; leftmost digits are filled with 0 ; Function to generate gray code ; Generate gray code of corresponding binary number of integer i . ; printing gray code ; Driver code
using System ; class GFG { static void decimalToBinaryNumber ( int x , int n ) { int [ ] binaryNumber = new int [ x ] ; int i = 0 ; while ( x > 0 ) { binaryNumber [ i ] = x % 2 ; x = x / 2 ; i ++ ; } for ( int j = 0 ; j < n - i ; j ++ ) Console . Write ( '0' ) ; for ( int j = i - 1 ; j >= 0 ; j -- ) Console . Write ( binaryNumber [ j ] ) ; } static void generateGrayarr ( int n ) { int N = 1 << n ; for ( int i = 0 ; i < N ; i ++ ) { int x = i ^ ( i >> 1 ) ; decimalToBinaryNumber ( x , n ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int n = 3 ; generateGrayarr ( n ) ; } }
Sum of bitwise AND of all possible subsets of given set | C # program to calculate sum of Bit - wise and sum of all subsets of an array ; assuming representation of each element is in 32 bit ; iterating array element ; Counting the set bit of array in ith position ; counting subset which produce sum when particular bit position is set . ; multiplying every position subset with 2 ^ i to count the sum . ; Drivers code
using System ; class GFG { static int BITS = 32 ; static int andSum ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < BITS ; i ++ ) { int countSetBits = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & ( 1 << i ) ) != 0 ) countSetBits ++ ; } int subset = ( 1 << countSetBits ) - 1 ; subset = ( subset * ( 1 << i ) ) ; ans += subset ; } return ans ; } static public void Main ( ) { int [ ] arr = { 1 , 2 , 3 } ; int size = 3 ; Console . WriteLine ( andSum ( arr , size ) ) ; } }
Maximize the number by rearranging bits | An efficient C # program to find minimum number formed by bits of a given number . ; Returns maximum number formed by bits of a given number . ; _popcnt32 ( a ) gives number of 1 's present in binary  representation of a. ; If along 32 bits are set . ; find a number witn n least significant set bits . ; Now shift result by 32 - n ; Driver Code
using System ; class GFG { static long _popcnt32 ( long n ) { long count = 0 ; while ( n != 0 ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } static long maximize ( long a ) { long n = _popcnt32 ( a ) ; if ( n == 32 ) return a ; long res = ( 1 << Convert . ToInt32 ( n ) ) - 1 ; return ( res << ( 32 - Convert . ToInt32 ( n ) ) ) ; } static void Main ( ) { long a = 3 ; Console . WriteLine ( maximize ( a ) ) ; } }
Minimum number using set bits of a given number | An efficient C # program to find minimum number formed by bits of a given number . ; Returns minimum number formed by bits of a given number . ; _popcnt32 ( a ) gives number of 1 's present in binary   representation of a. ; Driver Code .
using System ; using System . Linq ; using System . Collections . Generic ; class GFG { static long minimize ( long a ) { string binaryString = Convert . ToString ( a , 2 ) ; int n = binaryString . Split ( new [ ] { '0' } , StringSplitOptions . RemoveEmptyEntries ) . Length + 1 ; return ( ( long ) Math . Pow ( 2 , n ) - 1 ) ; } static void Main ( ) { long a = 11 ; Console . Write ( minimize ( a ) ) ; } }
Maximum steps to transform 0 to X with bitwise AND | C # code to find the maximum possible effort ; Function to get no . of set bits in binary representation of positive integer n ; Driver code
using System ; class GFG { static int countSetBits ( int n ) { int count = 0 ; while ( n != 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } public static void Main ( String [ ] args ) { int i = 3 ; Console . Write ( countSetBits ( i ) ) ; } }
Check a number is odd or even without modulus operator | A simple C # program to check for even or odd ; Returns true if n is even , else odd ; Driver code
using System ; public class GFG { static bool isEven ( int n ) { bool isEven = true ; for ( int i = 1 ; i <= n ; i ++ ) isEven = ! isEven ; return isEven ; } public static void Main ( ) { int n = 101 ; if ( isEven ( n ) ) Console . Write ( " Even " ) ; else Console . Write ( " Odd " ) ; } }
Check a number is odd or even without modulus operator | A simple C # program to check for even or odd ; Returns true if n is even , else odd ; Return true if n / 2 does not result in a float value . ; Driver code
using System ; class GFG { static bool isEven ( int n ) { return ( ( n / 2 ) * 2 == n ) ; } public static void Main ( String [ ] args ) { int n = 101 ; if ( isEven ( n ) != false ) Console . Write ( " Even " ) ; else Console . Write ( " Odd " ) ; } }
Bitwise recursive addition of two integers | C # program to do recursive addition of two integers ; If bitwise & is 0 , then there is not going to be any carry . Hence result of XOR is addition . ; Driver code
using System ; class GFG { static int add ( int x , int y ) { int keep = ( x & y ) << 1 ; int res = x ^ y ; if ( keep == 0 ) return res ; return add ( keep , res ) ; } public static void Main ( ) { Console . Write ( add ( 15 , 38 ) ) ; } }
Count pairs in an array which have at least one digit common | C # Program to count pairs in an array with some common digit ; Returns true if the pair is valid , otherwise false ; converting integers to strings ; Iterate over the strings and check if a character in first string is also present in second string , return true ; No common digit found ; Returns the number of valid pairs ; Iterate over all possible pairs ; Driver Code to test above functions
using System ; class GFG { static bool checkValidPair ( int num1 , int num2 ) { string s1 = num1 . ToString ( ) ; string s2 = num2 . ToString ( ) ; for ( int i = 0 ; i < s1 . Length ; i ++ ) for ( int j = 0 ; j < s2 . Length ; j ++ ) if ( s1 [ i ] == s2 [ j ] ) return true ; return false ; } static int countPairs ( int [ ] arr , int n ) { int numberOfPairs = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( checkValidPair ( arr [ i ] , arr [ j ] ) ) numberOfPairs ++ ; return numberOfPairs ; } static void Main ( ) { int [ ] arr = new int [ ] { 10 , 12 , 24 } ; int n = arr . Length ; Console . WriteLine ( countPairs ( arr , n ) ) ; } }
Check if bitwise AND of any subset is power of two | C # Program to check if Bitwise AND of any subset is power of two ; Check for power of 2 or not ; Check if there exist a subset whose bitwise AND is power of 2. ; if there is only one element in the set . ; Finding a number with all bit sets . ; check all the positions at which the bit is set . ; include all those elements whose i - th bit is set ; check for the set contains elements make a power of 2 or not ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int NUM_BITS = 32 ; static bool isPowerOf2 ( int num ) { if ( num != 0 && ( num & ( num - 1 ) ) == 0 ) return true ; return false ; } static bool checkSubsequence ( int [ ] arr , int n ) { if ( n == 1 ) return isPowerOf2 ( arr [ 0 ] ) ; int total = 0 ; for ( int i = 0 ; i < NUM_BITS ; i ++ ) total = total | ( 1 << i ) ; for ( int i = 0 ; i < NUM_BITS ; i ++ ) { int ans = total ; for ( int j = 0 ; j < n ; j ++ ) { int p = arr [ j ] & ( 1 << i ) ; if ( p == 0 ) ans = ans & arr [ j ] ; } if ( isPowerOf2 ( ans ) ) return true ; } return false ; } public static void Main ( ) { int [ ] arr = { 12 , 13 , 7 } ; int n = arr . Length ; if ( checkSubsequence ( arr , n ) ) Console . Write ( " YES STRNEWLINE " ) ; else Console . Write ( " NO STRNEWLINE " ) ; } }
Levelwise Alternating OR and XOR operations in Segment Tree | C # program to build levelwise OR / XOR alternating Segment tree ; A utility function to get the middle index from corner indexes . ; A recursive function that constructs Segment Tree for array [ ss . . se ] . si is index of current node in segment tree st operation denotes which operation is carried out at that level to merge the left and right child . It 's either 0 or 1. ; If there is one element in array , store it in current node of segment tree and return ; If there are more than one elements , then recur for left and right subtrees and store the sum of values in this node ; Build the left and the right subtrees by using the fact that operation at level ( i + 1 ) = ! ( operation at level i ) ; Merge the left and right subtrees by checking the operation to be carried . If operation = 1 , then do OR else XOR ; OR operation ; XOR operation ; Function to construct segment tree from given array . This function allocates memory for segment tree and calls constructSTUtil ( ) to fill the allocated memory ; Height of segment tree ; Maximum size of segment tree ; Allocate memory ; Operation = 1 ( XOR ) if Height of tree is even else it is 0 ( OR ) for the root node ; Fill the allocated memory st ; Return the constructed segment tree ; Driver Code ; Leaf nodes ; Build the segment tree ; Root node is at index 0 considering 0 - based indexing in segment Tree ; Print value at rootIndex
using System ; class GFG { static int getMid ( int s , int e ) { return s + ( e - s ) / 2 ; } static void constructSTUtil ( int [ ] arr , int ss , int se , int [ ] st , int si , bool operation ) { if ( ss == se ) { st [ si ] = arr [ ss ] ; return ; } int mid = getMid ( ss , se ) ; constructSTUtil ( arr , ss , mid , st , si * 2 + 1 , ! operation ) ; constructSTUtil ( arr , mid + 1 , se , st , si * 2 + 2 , ! operation ) ; if ( operation ) { st [ si ] = ( st [ 2 * si + 1 ] st [ 2 * si + 2 ] ) ; } else { st [ si ] = ( st [ 2 * si + 1 ] ^ st [ 2 * si + 2 ] ) ; } } static int [ ] constructST ( int [ ] arr , int n ) { int x = ( int ) ( Math . Ceiling ( Math . Log ( n ) / Math . Log ( 2 ) ) ) ; int max_size = 2 * ( int ) Math . Pow ( 2 , x ) - 1 ; int [ ] st = new int [ max_size ] ; bool operationAtRoot = ! ( x % 2 == 0 ) ; constructSTUtil ( arr , 0 , n - 1 , st , 0 , operationAtRoot ) ; return st ; } static public void Main ( ) { int [ ] leaves = { 1 , 6 , 3 , 7 , 5 , 9 , 10 , 4 } ; int n = leaves . Length ; int [ ] segmentTree = constructST ( leaves , n ) ; int rootIndex = 0 ; Console . WriteLine ( " Value ▁ at ▁ Root ▁ Node ▁ = ▁ " + segmentTree [ rootIndex ] ) ; } }
Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs | C # program to print the Leftover element after performing alternate Bitwise OR and Bitwise XOR operations to the pairs . ; count the step number ; if one element is there , it will be the answer ; at first step we do a bitwise OR ; keep on doing bitwise operations till the last element is left ; perform operations ; if step is the odd step ; else even step ; answer when one element is left ; Driver Code ; 1 st query ; 2 nd query
using System ; using System . Collections . Generic ; class GFG { static int N = 1000 ; static int lastElement ( int [ ] a , int n ) { int steps = 1 ; List < int > [ ] v = new List < int > [ N ] ; for ( int i = 0 ; i < N ; i ++ ) v [ i ] = new List < int > ( ) ; if ( n == 1 ) return a [ 0 ] ; for ( int i = 0 ; i < n ; i += 2 ) v [ steps ] . Add ( a [ i ] a [ i + 1 ] ) ; while ( v [ steps ] . Count > 1 ) { steps += 1 ; for ( int i = 0 ; i < v [ steps - 1 ] . Count ; i += 2 ) { if ( steps % 2 == 1 ) v [ steps ] . Add ( v [ steps - 1 ] [ i ] v [ steps - 1 ] [ i + 1 ] ) ; v [ steps ] . Add ( v [ steps - 1 ] [ i ] ^ v [ steps - 1 ] [ i + 1 ] ) ; } } return v [ steps ] [ 0 ] ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 4 , 5 , 6 } ; int n = a . Length ; int index = 0 ; int value = 2 ; a [ 0 ] = 2 ; Console . WriteLine ( lastElement ( a , n ) ) ; index = 3 ; value = 5 ; a [ index ] = value ; Console . WriteLine ( lastElement ( a , n ) ) ; } }
Find the winner in nim | C # to find nim - game winner ; function to find winner of NIM - game ; case when Alice is winner ; when Bob is winner ; Driver code
using System ; class GFG { static String findWinner ( int [ ] A , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res ^= A [ i ] ; if ( res == 0 n % 2 == 0 ) return " Alice " ; else return " Bob " ; } public static void Main ( ) { int [ ] A = { 1 , 4 , 3 , 5 } ; int n = A . Length ; Console . WriteLine ( " Winner ▁ = ▁ " + findWinner ( A , n ) ) ; } }
Fibbinary Numbers ( No consecutive 1 s in binary ) | C # implementation to check whether a number is fibbinary or not ; function to check whether a number is fibbinary or not ; if the number does not contain adjacent ones then ( n & ( n >> 1 ) ) operation results to 0 ; not a fibbinary number ; Driver program to test above
using System ; class GFG { static bool isFibbinaryNum ( int n ) { if ( ( n & ( n >> 1 ) ) == 0 ) return true ; return false ; } public static void Main ( ) { int n = 10 ; if ( isFibbinaryNum ( n ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Maximum XOR | Program to obtain maximum XOR value sub - array ; function to calculate maximum XOR value ; Return ( 2 ^ c - 1 ) ; Driver Code
using System ; class GFG { static int maxXOR ( int n , int k ) { int c = ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) + 1 ; return ( ( 1 << c ) - 1 ) ; } public static void Main ( String [ ] args ) { int n = 12 ; int k = 3 ; Console . Write ( maxXOR ( n , k ) ) ; } }
Divide two integers without using multiplication , division and mod operator | C # implementation to Divide two integers without using multiplication , division and mod operator ; Function to divide a by b and return floor value it ; Calculate sign of divisor i . e . , sign will be negative only iff either one of them is negative otherwise it will be positive ; remove sign of operands ; Initialize the quotient ; test down from the highest bit and accumulate the tentative value for valid bit ; if the sign value computed earlier is - 1 then negate the value of quotient ; Driver code
using System ; class GFG { public static long divide ( long dividend , long divisor ) { long sign = ( ( dividend < 0 ) ^ ( divisor < 0 ) ) ? - 1 : 1 ; dividend = Math . Abs ( dividend ) ; divisor = Math . Abs ( divisor ) ; long quotient = 0 , temp = 0 ; for ( int i = 31 ; i >= 0 ; -- i ) { if ( temp + ( divisor << i ) <= dividend ) { temp += divisor << i ; quotient |= 1L L << i ; } } if ( sign == - 1 ) quotient = - quotient ; return quotient ; } public static void Main ( ) { int a = 10 , b = 3 ; Console . WriteLine ( divide ( a , b ) ) ; int a1 = 43 , b1 = - 8 ; Console . WriteLine ( divide ( a1 , b1 ) ) ; } }
XOR of two numbers after making length of their binary representations equal | C # implementation to return XOR of two numbers after making length of their binary representation same ; function to count the number of bits in binary representation of an integer ; initialize count ; count till n is non zero ; right shift by 1 i . e , divide by 2 ; function to calculate the xor of two numbers by adding trailing zeros to the number having less number of bits in its binary representation . ; stores the minimum and maximum ; left shift if the number of bits are less in binary representation ; driver code to check the above function
using System ; class GFG { static int count ( int n ) { int c = 0 ; while ( n != 0 ) { c ++ ; n = n >> 1 ; } return c ; } static int XOR ( int a , int b ) { int c = Math . Min ( a , b ) ; int d = Math . Max ( a , b ) ; if ( count ( c ) < count ( d ) ) c = c << ( count ( d ) - count ( c ) ) ; return ( c ^ d ) ; } public static void Main ( ) { int a = 13 , b = 5 ; Console . WriteLine ( XOR ( a , b ) ) ; } }
Check if binary string multiple of 3 using DFA | C # program to check if the binary String is divisible by 3. ; Function to check if the binary String is divisible by 3. ; checking if the bit is nonzero ; checking if the nonzero bit is at even position ; Checking if the difference of non - zero oddbits and evenbits is divisible by 3. ; Driver Program
using System ; public class GFG { static void CheckDivisibilty ( String A ) { int oddbits = 0 , evenbits = 0 ; for ( int counter = 0 ; counter < A . Length ; counter ++ ) { if ( A [ counter ] == '1' ) { if ( counter % 2 == 0 ) { evenbits ++ ; } else { oddbits ++ ; } } } if ( Math . Abs ( oddbits - evenbits ) % 3 == 0 ) { Console . Write ( " Yes " + " STRNEWLINE " ) ; } else { Console . Write ( " No " + " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { String A = "10101" ; CheckDivisibilty ( A ) ; } }
Swap every two bits in bytes | C # program to swap every two bits in a byte . ; Extracting the high bit shift it to lowbit Extracting the low bit shift it to highbit ; Driver function to test above function
using System ; public class GFG { static uint swapBitsInPair ( uint x ) { return ( ( x & 010101010 ) >> 1 ) | ( ( x & 001010101 ) << 1 ) ; } static public void Main ( ) { uint x = 4 ; Console . WriteLine ( swapBitsInPair ( x ) ) ; } }
Alternate bits of two numbers to create a new number | C # Program to generate a number using alternate bits of two numbers . ; set even bit of number n ; res for store 101010. . number ; generate number form of 101010. . ... till temp size ; if bit is even then generate number and or with res ; return set even bit number ; set odd bit of number m ; res for store 101010. . number ; generate number form of 101010. . . . till temp size ; if bit is even then generate number and or with res ; return set odd bit number ; set even bit of number n ; set odd bit of number m ; take OR with these number ; Driver code ; n = 1 0 1 0 ^ ^ m = 1 0 1 1 ^ ^ result = 1 0 1 1
using System ; class GFG { static int setevenbits ( int n ) { int temp = n ; int count = 0 ; int res = 0 ; for ( temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return ( n & res ) ; } static int setoddbits ( int m ) { int count = 0 ; int res = 0 ; for ( int temp = m ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 0 ) res |= ( 1 << count ) ; count ++ ; } return ( m & res ) ; } static int getAlternateBits ( int n , int m ) { int tempn = setevenbits ( n ) ; int tempm = setoddbits ( m ) ; return ( tempn tempm ) ; } public static void Main ( ) { int n = 10 ; int m = 11 ; Console . WriteLine ( getAlternateBits ( n , m ) ) ; } }
Decimal representation of given binary string is divisible by 20 or not | C # implementation to check whether decimal representation of given binary number is divisible by 20 or not ; function to check whether decimal representation of given binary number is divisible by 10 or not ; if last digit is '1' , then number is not divisible by 10 ; to accumulate the sum of last digits in perfect powers of 2 ; traverse from the 2 nd last up to 1 st digit in ' bin ' ; if digit in '1' ; calculate digit 's position from  the right ; according to the digit 's position,  obtain the last digit of the  applicable perfect power of 2 ; if last digit is 0 , then divisible by 10 ; not divisible by 10 ; function to check whether decimal representation of given binary number is divisible by 20 or not ; if ' bin ' is an odd number ; check if bin ( 0. . n - 2 ) is divisible by 10 or not ; Driver program to test above
using System ; class GFG { static bool isDivisibleBy10 ( string bin , int n ) { if ( bin [ n - 1 ] == '1' ) return false ; int sum = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( bin [ i ] == '1' ) { int posFromRight = n - i - 1 ; if ( posFromRight % 4 == 1 ) sum = sum + 2 ; else if ( posFromRight % 4 == 2 ) sum = sum + 4 ; else if ( posFromRight % 4 == 3 ) sum = sum + 8 ; else if ( posFromRight % 4 == 0 ) sum = sum + 6 ; } } if ( sum % 10 == 0 ) return true ; return false ; } static bool isDivisibleBy20 ( string bin , int n ) { if ( bin [ n - 1 ] == '1' ) return false ; return isDivisibleBy10 ( bin , n - 1 ) ; } public static void Main ( ) { string bin = "101000" ; int n = bin . Length ; if ( isDivisibleBy20 ( bin , n - 1 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
For every set bit of a number toggle bits of other | C # program toggle bits of n2 that are at same position as set bits of n1 . ; function for the Nega_bit ; Driver program
using System ; class GFG { static int toggleBits ( int n1 , int n2 ) { return ( n1 ^ n2 ) ; } public static void Main ( ) { int n1 = 2 , n2 = 5 ; Console . WriteLine ( toggleBits ( n1 , n2 ) ) ; } }
Toggle all even bits of a number | C # code to Toggle all even bit of a number ; Returns a number which has all even bits of n toggled . ; Generate number form of 101010 . . till of same order as n ; if bit is even then generate number and or with res ; return toggled number ; Driver code
using System ; class GFG { static int evenbittogglenumber ( int n ) { int res = 0 , count = 0 ; for ( int temp = n ; temp > 0 ; temp >>= 1 ) { if ( count % 2 == 1 ) res |= ( 1 << count ) ; count ++ ; } return n ^ res ; } public static void Main ( ) { int n = 11 ; Console . WriteLine ( evenbittogglenumber ( n ) ) ; } }