package scpj2.three;
public class Binary {
public static void main(String[] args){
System.out.println(makeBinaryString(22));
int aa= 1;
int bb = 22;
bb >>>=aa;
System.out.println("22的2进制: "+Integer.toBinaryString(22));
System.out.println("24的2进制: "+Integer.toBinaryString(24));
System.out.println("11的2进制: "+Integer.toBinaryString(11));
System.out.println("bb >>>1= "+bb);
System.out.println("22 & 1= "+(22 & 1));
System.out.println("11 & 1= "+(11 & 1));
}
public static String makeBinaryString(int i){
/*This section could have been optimized using
* StringBufer,but is pressented in this way for the
* sake of simplicity.
*/
String binary = "";
do{
System.out.println("i>>>前:"+i);
int lowBit = (i & 1);
System.out.println("低位lowBit=(i & 1):"+(i & 1));
String newDigit = ((lowBit == 0) ? "0" : "1");
binary = newDigit + binary;
i >>>= 1;
System.out.println("i>>>后:"+i);
}while (i != 0);
return binary;
}
}