text: Turn off the rightmost set bit | Set 2 | C # program to unset the rightmost set bit ; Unsets the rightmost set bit of n and returns the result ; Checking whether bit position is set or not ; If bit position is found set , we flip this bit by xoring given number and number with bit position set ; Driver code
code: using System ; class GFG { static void FlipBits ( int n ) { for ( int bit = 0 ; bit < 32 ; bit ++ ) { if ( ( n >> bit ) % 2 > 0 ) { n = n ^ ( 1 << bit ) ; break ; } } Console . Write ( " The ▁ number ▁ after ▁ unsetting ▁ the ▁ " ) ; Console . Write ( " rightmost ▁ set ▁ bit ▁ " + n ) ; } static void Main ( ) { int N = 12 ; FlipBits ( N ) ; } }