码迷,mamicode.com
首页 > 编程语言 > 详细

算法之将一个16进制的字符串转换成整数返回

时间:2017-07-02 20:27:58      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:for   bsp   rac   i++   char   nbsp   字符串   string   color   

public class HexToInt {
    public static void main(String[] args) {
        String str = "13abf";
        convert(str);
        
    }
    private static int convert(String str) {
        int len = str.length();
        int sum = 0;
        for (int i = 0; i < len; i++) {
            char c = str.charAt(len-1-i);
            int n = Character.digit(c, 16);
            sum += n*(1<<(4*i));
        }
        return sum;
    }
}

 

算法之将一个16进制的字符串转换成整数返回

标签:for   bsp   rac   i++   char   nbsp   字符串   string   color   

原文地址:http://www.cnblogs.com/lxcmyf/p/7106969.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!