Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bitwise operations program #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Java/Bitwise-Operations/Bitwise.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.io.*;

public class Bitwise {
public static void main(String args[])throws IOException {
DataInputStream d=new DataInputStream(System.in);
System.out.println("enter value for x:");
int x=Integer.parseInt(d.readLine());
System.out.println("\n enter value for y:");
int y= Integer.parseInt(d.readLine());
int choice;
do {
System.out.println("**********************");
System.out.println("1.Bitwise AND");
System.out.println("2.Bitwise OR");
System.out.println("3.Bitwise XOR");
System.out.println("4.Bitwise LEFT SHIFT");
System.out.println("5.Bitwise RIGHT SHIFT");
System.out.println("6.Bitwise NOT");
System.out.println("7.EXIT");
System.out.println("***********************");
System.out.println("enter your choice:");
choice=Integer.parseInt(d.readLine());
switch(choice) {
case 1:
System.out.println("Bitwise AND OPERATION:"+(x&y));
break;
case 2:
System.out.println("Bitwise OR OPERATION:"+(x|y));
break;
case 3:
System.out.println("Bitwise XOR OPERATION:"+(x^y));
break;
case 4:
System.out.println("LEFT SHIFT:"+(x<<y));
break;
case 5:
System.out.println("RIGHT SHIFT:"+(x>>y));
break;
case 6:
System.out.println("NOT of x :"+(~x));
System.out.println("NOT of y :"+(~y));
break;
case 7:
System.out.println("Thankyou");
System.exit(1);
break;
default:
System.out.println("Invalid chioce, Please enter the correct choice");
}
} while(choice!=7);
}
}
205 changes: 205 additions & 0 deletions Java/Bitwise-Operations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
## Expected Output

Enter value for x:

4



Enter value for y:

2

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

1

Bitwise AND OPERATION:0

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

2

Bitwise OR OPERATION:6

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

3

Bitwise XOR OPERATION:6

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

4

LEFT SHIFT:16

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

5

RIGHT SHIFT:1

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

6

NOT of x :-5

NOT of y :-3

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

8

Invalid chioce, Please enter the correct choice

**********************

1.Bitwise AND

2.Bitwise OR

3.Bitwise XOR

4.Bitwise LEFT SHIFT

5.Bitwise RIGHT SHIFT

6.Bitwise NOT

7.EXIT

***********************

enter your choice:

7

Thankyou