#include<stdio.h>
#include<conio.h> void main() { int a,b,t; clrscr(); printf("enter the two numbers:"); scanf("%d%d",&a,&b); printf("\nbefore swaping:%d & %d",a,b); a=a^b; b=a^b; a=a^b; printf("\nafter the swaping:%d & %d",a,b); getch(); } |
Output:-
Enter the two numbers: 7 4 Before swapping:7 & 4 After swapping: 4 & 7 |
* Write a program to using Bit-wise OR Operator.
#include<stdio.h> #include<conio.h> void main() { int x,y,z; clrscr(); x=10,y=15,z=x|y; printf(“z value is=%d”, z); getch(); } |
Output:-
Z value
is=15
|
X=10 – 1
0 1 0
|
Y=15
- 1 1 1 1
|
|
Z=15
- 1 1 1 1 (x | y)
|
* Write a program to using Bit-wise AND Operator.
#include<stdio.h> #include<conio.h> void main() { int x,y,z; clrscr(); x=10,y=15,z=x&y; printf(“z value is=%d”, z); getch(); } |
Output:-
Z value
is=10
|
X=10 – 1
0 1 0
|
Y=15
- 1 1 1 1
|
|
Z=10 - 1
0 1 0 (x & y)
|
* Write a program to using Bit-wise XOR Operator.
#include<stdio.h> #include<conio.h> void main() { int x,y,z; clrscr(); x=10,y=15,z=x^y; printf(“z value is=%d”, z); getch(); } |
Output:-
Z value
is=5
|
X=10 – 1
0 1 0
|
Y=15
- 1 1 1 1
|
|
Z=5 - 0
1 0 1 (x ^ y)
|
* Write a program to using Right Shift & Left Shift Operators.
#include<stdio.h> #include<conio.h> void main() { int a=10; clrscr(); printf(“right shift operator=%d\n”,a>>2); printf(“left shift operator=%d\n”,a<<3); gecth(); } |
Output:-
Right shift operator=2 Left shift operator =80 |
* Write a program to using Bit-Wise AND,OR,X-OR Operators.
#include<stdio.h> #include<conio.h> void main() { Unsigned int a=60; Unsigned int b=13; int c=0; clrscr(); c=a&b; printf(“value of C is=%d\n”,c); c=a|b; printf(“value of C is=%d\n”,c); c=a^b; printf(“value of C is=%d\n”,c); getch(); } |
Output:-
value of C is=12 value of C is=61 value of C is=49 |
__________________________________________________________________________________
__________________________________________________________________________________
__________________________________________________________________________________
Post a Comment