八进制转十进制代码

 1 public class EightToTen {
 2     public static void main(String[] args) {
 3         //得到要转换的值
 4         int n=345;
 5         //声明一个x得到转化后的值
 6         long x=0;
 7         //声明count 来统计此时的基为多少
 8         long count=1;
 9         // 将二进制数转化为十进制
10         while(n>0){
11             x=x+n%10*count;     //得到最后一位数并乘以基加到x上
12             n=n/10;
13             count=count*8;
14         }
15         System.out.println("0345转换后的十进制为:"+x);
16 
17     }

猜你喜欢

转载自www.cnblogs.com/scwyqin/p/12411566.html