Flip all K | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void flippingBits ( unsigned long N , unsigned long K ) { unsigned long X = ( 1 << ( K - 1 ) ) - 1 ; N = X - N ; cout << N ; } int main ( ) { unsigned long N = 1 , K = 8 ; flippingBits ( N , K ) ; return 0 ; }