public static void main(String[] args) {
int num = 23;
StringBuilder sb = new StringBuilder();
int temp;
while(num > 0) {
temp = num % 2;
sb.append(temp);
num /= 2;
}
System.out.println(sb.reverse().toString());
}
public class Test
{
public static void main(String[]args){
int a=23;
int b=a;
String result="";
while(a!=0){
result=(a%2)+result;
a/=2;
}
System.out.println(b+"的二进制为:"+result);
result=Integer.toBinaryString(b);
System.out.println(b+"的二进制为:"+result);
}
}