Program to toggle K | C # program to toggle K - th bit of a number N ; Function to toggle the kth bit of n ; Driver code
using System ; class GFG { static int toggleBit ( int n , int k ) { return ( n ^ ( 1 << ( k - 1 ) ) ) ; } public static void Main ( String [ ] args ) { int n = 5 , k = 2 ; Console . WriteLine ( " { 0 } " , toggleBit ( n , k ) ) ; } }