输出整数的二进制

直接上代码
Scanner scan = new Scanner(System.in);  
        System.out.println("请输入一个整数:");  
        int number = scan.nextInt();  
          
        int tmp = 1<<31; //用于计算的临时变量  
          
        System.out.println();  
        for(int i=0; i<Integer.SIZE-1; i++) {  
            //System.out.print(number &(tmp>>>=1));
            //System.out.print(number & (temp>>>(i+1))>0?1:0);
            System.out.print( (number &(tmp>>>=1))>0? 1:0);  
        }  
        System.out.println();  
        if(scan != null) {  
            scan.close();  
        } 



转载出处:

http://blog.csdn.net/yfstdio/article/details/25079563

你可能感兴趣的:(java)