- 论坛徽章:
- 0
|
public class TenToTwo {
public static String change(long DecNumber) {
String BinNumber = "";
for (int i = 64; i >= 0; i--) {
if (DecNumber / (long) (Math.pow(2, i)) == 1) {
BinNumber = BinNumber + "1";
DecNumber = (long) (DecNumber - Math.pow(2, i));
} else {
if (!BinNumber.equals("")) {
BinNumber = BinNumber + "0";
}
}
}
return BinNumber;
}
/**
* @param args
*/
public static void main(String[] args) {
long DecNumber = 456;
System.out.println(TenToTwo.change(DecNumber));
}
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/50183/showart_426119.html |
|