位运算符
~ -- 取反 & -- 按位与 | -- 按位或 ^ -- 按位异或
<<:左移运算符, >>:右移运算符 >>>:无符号移位运算符
左移一位相当于乘2。右移一位相当于除2取商。
public class TestOperator{ public static void main(String[] args) { int a = 3; int b = a++; //执行完后,b=3。先给b赋值,再自增。 int c = ++a; //执行完后,c=5。先自增,再给b赋值 System.out.println(a); System.out.println(b); System.out.println(c); System.out.println("-----------"); int a0 = 3; int a1 = 3<<1; int a2 = 3<<2; int a3 = 3<<3; System.out.println(a1); System.out.println(a2); System.out.println(a3); System.out.println("-----------"); int c0 = 24; int c1 = c0>>1; int c2 = c0>>2; int c3 = c0>>3; System.out.println(c1); System.out.println(c2); System.out.println(c3); } }