import java.util.Scanner; |
/** |
* 十进制转换为二进制(32位) |
* |
*/ |
public class ToBinary { |
public static void main(String[] args) { |
int n; |
Scanner s = new Scanner(System.in); |
System.out.println( "please input a number:" ); |
n = s.nextInt(); |
for ( int i = 31 ; i >= 0 ; i--) { |
if ((n & ( 1 << i)) != 0 ) { |
System.out.print( "1" ); |
} else { |
System.out.print( "0" ); |
} |
if (( 32 - i) % 8 == 0 ) { |
System.out.print( " " ); |
} |
} |
} |
} |
初级程序员
by: 洛云 发表于:2012-12-18 11:22:08 顶(1) | 踩(0) 回复
Integer.toBinaryString(
2012
)
回复评论