Table Of Contents
- 1. write a code for to find equal or not by using bitwise
- 2. write a code for to Find Odd or Even Using Bitwise
- 3. write a c code for Swap Two Numbers Using Bitwise
- 4. write a c code for to enable nth bit of 'num' using bitwise operators.
- 5. write a c code for to Check Nth Bit is Set or Unset
- 6. write a c code for Disable Nth Bit of a Number
- 7. write a c code for to Toggle Nth Bit of a Number
- 8. write a c code for Find the Odd Occuring Numbers Using Bitwise
1. write a code for to find equal or not by using bitwise
#include<stdio.h>
int main()
{
int num1, num2;
scanf("%d%d", &num1,&num2);
//Write your code here
if((num1 ^ num2) == 0)
printf("Equal");
else
printf("Unequal");
return 0;
}
2. write a code for to Find Odd or Even Using Bitwise
#include<stdio.h>
int main()
{
int num;
scanf("%d", &num);
//Write your code here
if((num & 1) == 0)
printf("Even");
else
printf("Odd");
return 0;
}
3. write a c code for Swap Two Numbers Using Bitwise
#include<stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
//Write your code here
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d", a, b);
return 0;
}
4. write a c code for to enable nth bit of ‘num’ using bitwise operators.
#include<stdio.h>
int main()
{
int num, n;
scanf("%d%d", &num,&n);
//Write your code here
num = num | (1 << (n-1));
printf("%d", num);
return 0;
}
5. write a c code for to Check Nth Bit is Set or Unset
#include<stdio.h>
int main()
{
int num, n;
scanf("%d%d", &num, &n);
//Write your code here
num = num & (1 << (n-1));
if(num == 0)
printf("OFF");
else
printf("ON");
return 0;
}
6. write a c code for Disable Nth Bit of a Number
#include<stdio.h>
int main()
{
int num, n;
scanf("%d%d", &num,&n);
//Write your code here
num = num & ~(1 << (n-1));
printf("%d", num);
return 0;
}
7. write a c code for to Toggle Nth Bit of a Number
#include<stdio.h>
int main()
{
int num, n;
scanf("%d%d", &num, &n);
//Write your code here
num = num ^ (1 << (n-1));
printf("%d", num);
return 0;
}
8. write a c code for Find the Odd Occuring Numbers Using Bitwise
#include<stdio.h>
int main()
{
int arr[10], size, i;
scanf("%d", &size);
for(i = 0; i < size; i++)
scanf("%d", &arr[i]);
//Write your code here
int odd_occurring = arr[0];
for(i = 1; i < size; i++)
odd_occurring ^= arr[i];
printf("%d", odd_occurring);
return 0;
}