- class TrasDemo {
- public static void main(String[] args) {
- //System.out.println("Hello World!");
- dicemalTransToBinary(14857817, 8);
- }
- //public static void dicemalTransToBinary(int num){
- //StringBuilder sb=new StringBuilder();
- //while(num!=0){
- //int i=num%2;
- //sb.append(i);
- //System.out.print(i);
- //num=num/2;
- //}
- //sb.reverse();
- //System.out.println();
- //System.out.println(sb);
- //}
- //==========================十进制转其他进制
-
- public static void dicemalTransToBinary(int num ,int radix) {
- //num十进制的数 radix 是进制基数
- StringBuffer sb=new StringBuffer();
- while(num!=0){
- int i=num%radix;
- sb.append(i);
- System.out.print(i);
- num=num/radix;
- }
- sb.reverse();
- System.out.println();
- System.out.println(sb);
- }
- }
复制代码
|
|