以前寫程式時,常需要將十進位的數字轉成二進位,再進行計算。
Java在Integer和Long Class有提供一個static method叫做toBinaryString(),我們可以很方便的使用它。
int num = 18;
System.out.println(Integer.toBinaryString(num));
結果會印出
10010
2007年7月21日 星期六
toBinaryString
訂閱:
張貼留言 (Atom)
You got a dream, you gotta protect it!
以前寫程式時,常需要將十進位的數字轉成二進位,再進行計算。
Java在Integer和Long Class有提供一個static method叫做toBinaryString(),我們可以很方便的使用它。
int num = 18;
System.out.println(Integer.toBinaryString(num));
結果會印出
10010
0 意見:
張貼留言