Set or Clear a Specific Bit in a Register

Code

#include <stdio.h>

int main()
{

  unsigned int n;
  unsigned bit,mod;
  
  scanf("%u",&n);
  scanf("%u",&bit);
  scanf("%u",&mod);



  if(mod==1)
  {
    n |=(1<<bit);
  }
  else if(mod==0)
  {
    n &=~(1<<bit);
  }
  else
  {
    printf("Invalid oparation ");

  }
  printf("%u",n);



  return 0;


}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

10 3 1

Expected Output

10