-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperator bitwase
61 lines (59 loc) · 2.59 KB
/
Operator bitwase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.bitwase;
public class Operator {
public static void main(String[] args){
int a,b,c;
String a_byte,b_byte,c_byte;
a = 24;
//operator ShifT Left
System.out.println("======SHIFT LEFT");
a_byte = String.format("%8s",Integer.toBinaryString(a)).replace(' ','0');
System.out.printf("%s = %d \n",a_byte,a);
b = (a << 2);
b_byte = String.format("%8s",Integer.toBinaryString(b)).replace(' ','0');
System.out.printf("%s = %d \n",b_byte,b);
// operator Shif right
System.out.println("======SHIFT RIGHT");
a = 6;
a_byte = String.format("%8s",Integer.toBinaryString(a)).replace(' ','0');
System.out.printf("%s = %d \n",a_byte,a);
b = (a >> 1);
b_byte = String.format("%8s",Integer.toBinaryString(b)).replace(' ','0');
System.out.printf("%s = %d \n",b_byte,b);
//OPERATOR OR
System.out.println("====== BITWASE OR");
a = 6;
a_byte = String.format("%8s",Integer.toBinaryString(a)).replace(' ','0');
System.out.printf("%s = %d \n",a_byte,a);
b = (a >> 1);
b_byte = String.format("%8s",Integer.toBinaryString(b)).replace(' ','0');
System.out.printf("%s = %d \n",b_byte,b);
System.out.println("--------OR");
c =(byte)(a | b);
c_byte = String.format("%8s",Integer.toBinaryString(c)).replace(' ','0');
System.out.printf("%s = %d \n",c_byte,c);
// operator and
System.out.println("====== BITWASE AND");
a = 6;
a_byte = String.format("%8s",Integer.toBinaryString(a)).replace(' ','0');
System.out.printf("%s = %d \n",a_byte,a);
b = (a >> 1);
b_byte = String.format("%8s",Integer.toBinaryString(b)).replace(' ','0');
System.out.printf("%s = %d \n",b_byte,b);
System.out.println("--------AND");
c =(byte)(a & b);
c_byte = String.format("%8s",Integer.toBinaryString(c)).replace(' ','0');
System.out.printf("%s = %d \n",c_byte,c);
//operator XOR
System.out.println("====== BITWASE XOR");
a = 6;
a_byte = String.format("%8s",Integer.toBinaryString(a)).replace(' ','0');
System.out.printf("%s = %d \n",a_byte,a);
b = (a >> 1);
b_byte = String.format("%8s",Integer.toBinaryString(b)).replace(' ','0');
System.out.printf("%s = %d \n",b_byte,b);
System.out.println("--------XOR");
c =(byte)(a ^ b);
c_byte = String.format("%8s",Integer.toBinaryString(c)).replace(' ','0');
System.out.printf("%s = %d \n",c_byte,c);
}
}