首页 > 编程语言 > 详细

进制转换算法

时间:2015-04-07 21:21:15      阅读:132      评论:0      收藏:0      [点我收藏+]
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

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

进制转换算法

原文:http://www.cnblogs.com/luankun0214/p/4399388.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!