浏览 2467 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-03-10
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; } }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |