package a.c.c;

import com.google.common.primitives.UnsignedBytes;
import com.ucar.vehiclesdk.connect.UCarConnectProxy;

public class b {
    public static int a(String str, int i, int i2) {
        try {
            return Integer.parseInt(str, i2);
        } catch (NumberFormatException unused) {
            return i;
        }
    }

    public static String a(int i) {
        String hexString = Integer.toHexString(i);
        if (hexString.length() % 2 == 1) {
            hexString = "0" + hexString;
        }
        return hexString.toUpperCase();
    }

    public static String a(int i, int i2) {
        String hexString = Integer.toHexString(i);
        if (hexString.length() % 2 == 1) {
            hexString = "0" + hexString;
        }
        return c(hexString.toUpperCase(), i2);
    }

    public static String a(String str) {
        StringBuilder sb = new StringBuilder();
        int length = str.length() / 2;
        for (int i = 0; i < length; i++) {
            int i2 = i * 2;
            sb.append(String.valueOf((char) d(str.substring(i2, i2 + 2))));
        }
        return sb.toString();
    }

    public static String a(String str, int i) {
        StringBuilder sb = new StringBuilder();
        int length = str.length() / i;
        int i2 = 0;
        while (i2 < length) {
            int i3 = i2 * i;
            i2++;
            sb.append((char) d(str.substring(i3, i2 * i)));
        }
        return sb.toString();
    }

    public static String a(byte[] bArr) {
        if (bArr != null) {
            StringBuilder sb = new StringBuilder();
            for (byte b : bArr) {
                String hexString = Integer.toHexString(b & UnsignedBytes.MAX_VALUE);
                if (hexString.length() == 1) {
                    sb.append("0").append(hexString);
                } else {
                    sb.append(hexString);
                }
            }
            return sb.toString().toUpperCase();
        }
        throw new IllegalArgumentException("Argument b ( byte array ) is null! ");
    }

    public static int b(String str) {
        int length = str.length();
        int i = 0;
        for (int i2 = length; i2 > 0; i2--) {
            i = (int) (((double) i) + (Math.pow(2.0d, (double) (length - i2)) * ((double) (str.charAt(i2 - 1) - '0'))));
        }
        return i;
    }

    public static int b(String str, int i) {
        try {
            return Integer.parseInt(str);
        } catch (NumberFormatException unused) {
            return i;
        }
    }

    public static String b(byte[] bArr) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bArr) {
            sb.append((char) b);
        }
        return sb.toString();
    }

    public static String c(String str, int i) {
        StringBuilder sb = new StringBuilder();
        for (int i2 = 0; i2 < i - str.length(); i2++) {
            sb.insert(0, "0");
        }
        return (((Object) sb) + str).substring(0, i);
    }

    public static byte[] c(String str) throws IllegalArgumentException {
        if (str.length() % 2 == 0) {
            char[] charArray = str.toCharArray();
            byte[] bArr = new byte[(str.length() / 2)];
            int length = str.length();
            int i = 0;
            int i2 = 0;
            while (i < length) {
                int i3 = i + 1;
                bArr[i2] = Integer.valueOf(Integer.parseInt("" + charArray[i] + charArray[i3], 16) & 255).byteValue();
                i = i3 + 1;
                i2++;
            }
            return bArr;
        }
        throw new IllegalArgumentException();
    }

    public static int d(String str) {
        String upperCase = str.toUpperCase();
        int length = upperCase.length();
        int i = 0;
        for (int i2 = length; i2 > 0; i2--) {
            char charAt = upperCase.charAt(i2 - 1);
            i = (int) (((double) i) + (Math.pow(16.0d, (double) (length - i2)) * ((double) ((charAt < '0' || charAt > '9') ? (charAt - 'A') + 10 : charAt - '0'))));
        }
        return i;
    }

    public static String e(String str) {
        String str2;
        String upperCase = str.toUpperCase();
        StringBuilder sb = new StringBuilder();
        int length = upperCase.length();
        for (int i = 0; i < length; i++) {
            char charAt = upperCase.charAt(i);
            switch (charAt) {
                case '0':
                    str2 = UCarConnectProxy.w;
                    break;
                case '1':
                    str2 = "0001";
                    break;
                case '2':
                    str2 = "0010";
                    break;
                case '3':
                    str2 = "0011";
                    break;
                case '4':
                    str2 = "0100";
                    break;
                case '5':
                    str2 = "0101";
                    break;
                case '6':
                    str2 = "0110";
                    break;
                case '7':
                    str2 = "0111";
                    break;
                case '8':
                    str2 = "1000";
                    break;
                case '9':
                    str2 = "1001";
                    break;
                default:
                    switch (charAt) {
                        case 'A':
                            str2 = "1010";
                            break;
                        case 'B':
                            str2 = "1011";
                            break;
                        case 'C':
                            str2 = "1100";
                            break;
                        case 'D':
                            str2 = "1101";
                            break;
                        case 'E':
                            str2 = "1110";
                            break;
                        case 'F':
                            str2 = "1111";
                            break;
                        default:
                            continue;
                    }
            }
            sb.append(str2);
        }
        return sb.toString();
    }

    public static byte[] f(String str) {
        int length = str.length() / 2;
        byte[] bArr = new byte[length];
        String e = e(str);
        int i = 0;
        while (i < length) {
            int i2 = i * 8;
            int i3 = i + 1;
            bArr[i] = (byte) b(e.substring(i2 + 1, i3 * 8));
            if (e.charAt(i2) == '1') {
                bArr[i] = (byte) (-bArr[i]);
            }
            i = i3;
        }
        return bArr;
    }

    public static String g(String str) {
        StringBuilder sb = new StringBuilder();
        int length = str.length();
        for (int i = 0; i < length; i++) {
            sb.append(Integer.toHexString(str.charAt(i)));
        }
        return sb.toString();
    }
}
