位运算第一节课

master
30980 2 years ago
parent c6bd792df8
commit 836de8f633

@ -0,0 +1,23 @@
package com.never;
public class BitOperation {
public static void main(String[] args) {
int a = 2 ;
int b = ~a+1;
int c = b>>2;
int d = b>>>2;
printBit(a);
printBit(b);
System.out.println(b);
printBit(c);
printBit(d);
System.out.println(c);
System.out.println(d);
}
private static void printBit(int num){
for(int i = 31; i >= 0; i--){
System.out.print((num & (1<<i)) == 0?'0':'1');
}
System.out.println();
}
}
Loading…
Cancel
Save