java 16进制 转 10进制 工具类分享

package com.hl.dziot.util;

import java.util.HashMap;
import java.util.Map;

/**
* 转换工具类
*
* @author hwx
* @date 2023/6/7
**/
public class ConverUtils {
/**
* 16进制 转 10进制
* @author hwx
*/
public static int covert(String content){
int number=0;
String [] HighLetter = {"A","B","C","D","E","F"};
Map<String,Integer> map = new HashMap<>();
for(int i = 0;i <= 9;i++){
map.put(i+"",i);
}
for(int j= 10;j<HighLetter.length+10;j++){
map.put(HighLetter[j-10],j);
}
String[]str = new String[content.length()];
for(int i = 0; i < str.length; i++){
str[i] = content.substring(i,i+1);
}
for(int i = 0; i < str.length; i++){
number += map.get(str[i])*Math.pow(16,str.length-1-i);
}
return number;
}
}
 
posted @ 2023-06-07 11:33  jiuchengi  阅读(256)  评论(0编辑  收藏  举报