package com.quyunshuo.androidbaseframemvvm.common.util;

public class CheckUtlis {
    public static boolean checkHex(String hexStr) {
        // 截取最后4位
        String last4 = hexStr.substring(Math.max(0, hexStr.length() - 4));

        // 分割前部分并求和
        int sum = 0;
        String frontPart = hexStr.substring(0, Math.max(0, hexStr.length() - 4));
        for (int i = 0; i < frontPart.length(); i += 2) {
            String hexPair = frontPart.substring(i, i + 2);
            sum += Integer.parseInt(hexPair, 16);
        }

        // 转换为十六进制并对比
        String sumHex = String.format("%04X", sum);
        return sumHex.equals(last4.toUpperCase());
    }

}
