用除基取余法,不断地除以基数(几进制,基数就是几)得到余数,直到商为0,再将余数倒着拼起来即可。
private static String toBinaryString(int number) {标签:int,yushu,number,toBinaryString,StringBuilder,sb,方法,十进制 From: https://www.cnblogs.com/liuxuefeng/p/17724290.html
StringBuilder sb = new StringBuilder();
while (true) {
if(number == 0)
break;
int yushu = number % 2;
sb.insert(0, yushu);
number = number / 2;
}
return sb.toString();
}