Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.69 KB | None | 0 0
  1.  
  2. package bitwiseapp;
  3.  
  4.  class BitwiseOperations {
  5.    
  6.     private int a;
  7.     private int b;
  8.  
  9.     public int getA() {
  10.         return a;
  11.     }
  12.  
  13.     public void setA(int a) {
  14.         this.a = a;
  15.     }
  16.  
  17.     public int getB() {
  18.         return b;
  19.     }
  20.  
  21.     public void setB(int b) {
  22.         this.b = b;
  23.     }
  24.    
  25.     public void ShowlntA(){
  26.         System.out.println("A is number:" + this.a);
  27.     }
  28.     public void ShowlntB(){
  29.          System.out.println("B is number:" + this.b);
  30.     }
  31.    
  32.     public void ShowBinaryA(){
  33.         System.out.println("A is binary:" + Integer.toBinaryString(this.a));
  34.         }
  35.     public void ShowBinaryB(){
  36.         System.out.println("B is binary:" + Integer.toBinaryString(this.b));
  37.     }
  38.    
  39.     public int bitwiseOr(){
  40.       return this.a | this.b ;
  41.      }
  42.     public int bitwiseAnd(){
  43.         return this.a & this.b ;
  44.      }
  45.         public int bitwiseXor(){
  46.          return this.a ^ this.b ;  
  47.      }
  48.        
  49.        public int getComplementOneA(){
  50.         return ~ this. a ;
  51.         }  
  52.        
  53.        public int  getShiftRightOneA(){
  54.          return this. a >> 1;  
  55.        }
  56.        public int   getShiftLeftOneA(){
  57.           return   this.a << 1 ;
  58.        }
  59.        
  60.        private int Ν ;
  61.        public int  getShiftRightA(){
  62.            return this. a >> Ν ;
  63.        }
  64.        
  65.      int setComplementOneA(){
  66.         int A=this.a;
  67.         return this.a=~A;
  68.     }
  69.     void setComplementOneAPirnter(){
  70.         System.out.println(Integer.toBinaryString(a));
  71.     }
  72.           }
  73.            
  74.        
  75.        
  76.    
  77.  
  78.    
  79.  
  80.  
  81.  
  82.  
  83.  
  84. public class BitwiseApp {
  85.  
  86.    
  87.     public static void main(String[] args) {
  88.         int a=3;
  89.         int b=1;
  90.        
  91.         BitwiseOperations value = new  BitwiseOperations();
  92.         value.getA();
  93.         value.setA(10);
  94.        
  95.        
  96.         value.getB();
  97.         value.setB(6);
  98.        
  99.          value.ShowlntA();
  100.         value.ShowlntB();
  101.        
  102.         value.ShowBinaryA();
  103.         value.ShowBinaryB();
  104.        
  105.         value.bitwiseAnd();
  106.          System.out.println("a || (a << b): " + (a | (a << b)) );
  107.         value.bitwiseOr();
  108.          System.out.println("a & b: " + (a & b));
  109.         value.bitwiseXor();
  110.          System.out.println("a ^ b: " + (a ^ b));
  111.        
  112.         value.getComplementOneA();
  113.         System.out.println(~a);
  114.         value.getShiftRightOneA();
  115.         System.out.println("a << 1: " + (a << 1));
  116.         value.getShiftLeftOneA();
  117.          System.out.println(" a >> 1: " + (a >> 1));
  118.        
  119.        
  120.         value.setComplementOneAPirnter();
  121.         System.out.println(Integer.toBinaryString(3));
  122.        
  123.        
  124.        
  125.     }
  126.    
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement