进制转换算法

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

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

你可能感兴趣的:(进制转换)