package com.zksy.common.utils;

/**
 * @author Administrator
 * @version 1.0
 * @project dh-server-micro
 * @description 进制转换
 * @date 2025/6/6 11:19:39
 */
public class DecimalConversion {
    /**
     * TODO 16进制转10进制
     * @param hex
     * @return String
     * @author Administrator
     * @date 2023/11/13 15:31:52
     */
    public static String hexToDecimalExample(String hex){
        String str = "";
        int decimal=Integer.parseInt(hex,16);
        if(String.valueOf(decimal).length() < 2){
            str = "0"+decimal;
        }else{
            str = String.valueOf(decimal);
        }
        int num = Integer.parseInt(str);
        if(num > 127){
            str = String.valueOf(hexToDecimal(num));
        }
        return str;
    }
    /**
     * TODO 十进制大于127为负值
     * @param hexString
     * @return int
     * @author Administrator
     * @date 2024/8/6 10:10:04
     */
    public static int hexToDecimal(int hexString) {
        int decimal = 256 - hexString;
        return -decimal;
    }
}
