进制转换算法

package com.lk.C;

import java.util.Stack;

public class Test3 {
    public static String getBinary(int decimal){
        Stack<Integer> stack = new Stack<Integer>();
        while(decimal != 0){
            stack.push(decimal % 2);//向栈中增加余数
            decimal = decimal / 2;//获得新商
        }
        StringBuffer sb = new StringBuffer();
        while(!stack.empty()){
            sb.append(stack.pop());
        }
        return sb.toString();
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(getBinary(64));
    }

}
1000000

这里是十进制转换成二进制

posted @ 2015-04-07 20:58  luankun0214  阅读(173)  评论(0编辑  收藏  举报