-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitCalc.java
More file actions
37 lines (28 loc) · 915 Bytes
/
BitCalc.java
File metadata and controls
37 lines (28 loc) · 915 Bytes
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
package com.chen.util;
/**
* 位运算例子
*
* @author Chen WeiJie
* @date 2018-03-23 14:58
**/
public class BitCalc {
public static void main(String[] args) {
int a = 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = a & b; /* 12 = 0000 1100 */
System.out.println("a & b = " + c);
c = a | b; /* 61 = 0011 1101 */
System.out.println("a | b = " + c);
c = a ^ b; /* 49 = 0011 0001 */
System.out.println("a ^ b = " + c);
c = ~a; /*-61 = 1100 0011 */
System.out.println("~a = " + c);
c = a << 2; /* 240 = 1111 0000 */
System.out.println("a << 2 = " + c);
c = a >> 2; /* 15 = 1111 */
System.out.println("a >> 2 = " + c);
c = a >>> 2; /* 15 = 0000 1111 */
System.out.println("a >>> 2 = " + c);
}
}