Flip all K | Java program for the above approach ; Function to flip all K - bits of an unsigned number N ; Stores ( 2 ^ K ) - 1 ; Update N ; Print the answer ; Driver Code
import java . util . * ; class GFG { static void flippingBits ( long N , long K ) { long X = ( 1 << ( K - 1 ) ) - 1 ; N = X - N ; System . out . print ( N ) ; } public static void main ( String [ ] args ) { long N = 1 , K = 8 ; flippingBits ( N , K ) ; } }