Modify a bit at a given position | Java program to modify a bit at position p in n to b . ; Returns modified n . ; Driver Code
import java . io . * ; class GFG { public static int modifyBit ( int n , int p , int b ) { int mask = 1 << p ; return ( n & ~ mask ) | ( ( b << p ) & mask ) ; } public static void main ( String [ ] args ) { System . out . println ( modifyBit ( 6 , 2 , 0 ) ) ; System . out . println ( modifyBit ( 6 , 5 , 1 ) ) ; } }