Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bitwiseapp;
- public class BitwiseOperations {
- private int a;
- private int b;
- public int getA() {
- return a;
- }
- public void setA(int a) {
- this.a = a;
- }
- public int getB() {
- return b;
- }
- public void setB(int b) {
- this.b = b;
- }
- public void showlntA() {
- System.out.println("A AS NUMBER " + this.a);
- }
- public void showlntB() {
- System.out.println("B AS NUMBER " + this.b);
- }
- public void showBinaryA(){
- System.out.println("A is binary:" + Integer.toBinaryString(this.a));
- }
- public void showBinaryB(){
- System.out.println("B is binary:" + Integer.toBinaryString(this.b));
- }
- public int bitwiseOr() {
- return this.a | this.b;
- }
- public int bitwiseAnd(){
- return this.a & this.b ;
- }
- public int bitwiseXor(){
- return this.a ^ this.b ;
- }
- public int getComplementOneA(){
- return ~ this. a ;
- }
- public int getShiftRightOneA() {
- return this.a >> 1;
- }
- public int getShiftLeftOneA() {
- return this.a << 1;
- }
- public int getShiftRightA(int N){
- return a>>N;
- }
- public int setComplementOneA(){
- int A=this.a;
- return this.a=~A;
- }
- void setComplementOneACheck(){
- System.out.println(Integer.toBinaryString(a));
- }
- };
- package bitwiseapp;
- public class BitwiseApp {
- public static void main(String[] args) {
- BitwiseOperations bo = new BitwiseOperations();
- bo.setA(10);
- bo.setB(7);
- bo.showlntA();
- bo.showlntB();
- bo.showBinaryA();
- bo.showBinaryB();
- System.out.println(" ");
- int k = bo.bitwiseOr();
- System.out.println("Bitwise or as integer " + k);
- bo.showBinaryA();
- System.out.println("Bitwise or binary " + Integer.toBinaryString(k));
- bo.showBinaryB();
- System.out.println(" ");
- int m = bo.bitwiseAnd();
- System.out.println("Bitwise or as integer " + m);
- bo.showBinaryA();
- System.out.println("Bitwise or binary " + Integer.toBinaryString(m));
- bo.showBinaryB();
- System.out.println(" ");
- int n = bo.bitwiseXor();
- System.out.println("Bitwise or as integer " + n);
- bo.showBinaryA();
- System.out.println("Bitwise or binary " + Integer.toBinaryString(n));
- bo.showBinaryB();
- bo.showBinaryA();
- int printComplement = bo.getComplementOneA();
- System.out.println(Integer.toBinaryString(printComplement));
- System.out.println(" ");
- bo.showBinaryA();
- int printShiftRightOne = bo.getShiftRightOneA();
- System.out.println(Integer.toBinaryString(printShiftRightOne));
- System.out.println(" ");
- bo.showBinaryA();
- int printShiftLeftOne = bo.getShiftLeftOneA();
- System.out.println(Integer.toBinaryString(printShiftLeftOne));
- System.out.println(" ");
- bo.showBinaryA();
- int shiftRightA = bo.getShiftRightA(2);
- System.out.println(Integer.toBinaryString(shiftRightA));
- System.out.println(" ");
- bo.showBinaryA();
- bo.setComplementOneA();
- bo.setComplementOneACheck();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement