zoukankan      html  css  js  c++  java
  • Java实现八进制正整数转化为十进制数

    public class Main {
        public static void main(String[] args) {
            System.out.println(convert(23,2));
    //        System.out.println(power(8,2));
        }
    
        private static int convert(int n, int i) {//n为输入的八进制数,i为位数
            int temp[] = new int[i];
            int result = 0;
            for(int j=0;j < i;j++){
                temp[j] = (n/power(10,i-j-1))%power(10,1);
                result += temp[j]*power(8,i-j-1);
    //            System.out.print(n + " " + temp[j] + " " + power(10,i-j-1) + " " + power(10,j) + "
    ");
            }
    //        System.out.println();
            return result;
        }
    
        private static int power(int i, int j) {
            int temp = 1;
            for(int k=0;k<j;k++){
                temp *= i;
            }
            return temp;
        }
    }

     对于输入的一个八位数,取得每一位的数字,例如:3254/1000%10 = 3(前面的/为取整,后面的%为取余数,注意为取得每位上的数字,取得整数部分后,然后取每个整数的个位数就可以了,也就是%10)。

  • 相关阅读:
    Win32 DPAPI加密编程
    .NET环境下的DPAPI加密编程
    Windows加密API的功能分类
    Windows加密API的层次
    Windows加密服务架构
    简单H5单页面真机调试
    vue中使用动画vue-particles
    particular.js
    sublime快捷键
    判断内核
  • 原文地址:https://www.cnblogs.com/lovexz/p/6730496.html
Copyright © 2011-2022 走看看