JAVA中的十進制轉換為二進制
關注:106 答案:5 mip版
解決時間 2021-02-08 10:44

提問者這笑,有多危險
2021-02-07 11:41
不要用函數
最佳答案

二級知識專家此生不換的執著
2021-02-07 12:59
public class test {
public static void main(String[] args) {
String m = Integer.toBinaryString(120);
System.out.println(m);
}
}
--------------------------------
public class test {
public static void main(String[] args) {
int m = 13;
String s = "";
while (m > 0) {
s = m % 2 + s;
m = m / 2;
}
System.out.println(s);
}
}
全部回答

1樓會有一股神秘感
2021-02-07 17:08
public class Bin
{
public static void main(String[] args)
{
StringBuffer sbf = toBin(5);
String str=sbf.reverse().toString();
System.out.println(str);
}
static StringBuffer toBin(int x)
{
StringBuffer result=new StringBuffer();
do{
result.append(x%2);
x/=2;
}while(x>0);
return result;
}
}

2樓是你的阿離
2021-02-07 16:13
simpledateformat objsdateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");
string strcurrenttime = objsdateformat.format(date類型的時間);
注:大寫的hh為24小時制,小寫的hh為12小時制,當然還可以在ss的後面加上 a,這樣可以在後面顯示上下文:顯示效果為“2008-03-24 17:00:14 下午”

3樓無字情書
2021-02-07 15:02
public static void main(String[] args) {
StringBuffer bi = new StringBuffer();
int x = 90;
do{
int y = x%2;
bi.insert(0,y+"");
x = (x - y) / 2;
}while(x > 0);
System.out.println(bi.toString());
}

4樓百合的盛世戀
2021-02-07 14:03
public class tobin {
public static void main(String[] args) {
int x = 17;//轉換前的十進制數
int num=0;
for(int y=x;y!=0;num++)y=y/2;//計算轉換後二進制數的位數
int[] bin = new int[num];//轉換後的二進制數
for(int i=num-1,y=x;i>=0;i--){
bin[i]=y%2;
y=y/2;
}
for(int i=0;i
System.out.print(bin[i]);
}
}
我要舉報
如以上問答内容為低俗/色情/暴力/不良/侵權的資訊,可以點下面連結進行舉報,我們會做出相應處理,感謝你的支援!
→點此我要舉報以上資訊!←
推薦資訊
大家都在看