package com.cvte.dss.ups.camera.utils;

import android.util.Log;
import io.netty.handler.codec.dns.DnsRecord;
import io.netty.handler.codec.memcache.binary.BinaryMemcacheOpcodes;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import kotlin.Metadata;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes.dex */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000&\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u0012\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0006\n\u0002\u0010\u0005\n\u0002\b\b\bÆ\u0002\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0014\u0010\u0015J)\u0010\b\u001a\u0004\u0018\u00010\u00072\b\u0010\u0003\u001a\u0004\u0018\u00010\u00022\u0006\u0010\u0005\u001a\u00020\u00042\u0006\u0010\u0006\u001a\u00020\u0004¢\u0006\u0004\b\b\u0010\tJ\u0015\u0010\u000b\u001a\u00020\u00072\u0006\u0010\n\u001a\u00020\u0002¢\u0006\u0004\b\u000b\u0010\fJ\u001d\u0010\u000f\u001a\u00020\u000e2\u0006\u0010\u0003\u001a\u00020\u00022\u0006\u0010\r\u001a\u00020\u0004¢\u0006\u0004\b\u000f\u0010\u0010R\u0016\u0010\u0011\u001a\u00020\u00078\u0002@\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0011\u0010\u0012R\u0016\u0010\u0013\u001a\u00020\u00078\u0002@\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0013\u0010\u0012¨\u0006\u0016"}, d2 = {"Lcom/cvte/dss/ups/camera/utils/BitUtils;", "", "", "bytes", "", "offset", "dateLen", "", "bytesToAscii", "([BII)Ljava/lang/String;", "data", "bytesToHexString", "([B)Ljava/lang/String;", "maxIndex", "", "getCheckSum", "([BI)B", "CHARSET", "Ljava/lang/String;", "TAG", "<init>", "()V", "lib_release"}, k = 1, mv = {1, 4, 0})
public final class BitUtils {
    private static final String CHARSET = "ISO8859-1";
    public static final BitUtils INSTANCE = new BitUtils();
    private static final String TAG = "BitUtils";

    private BitUtils() {
    }

    public final String bytesToAscii(byte[] bytes, int offset, int dateLen) {
        if (bytes == null) {
            return null;
        }
        if ((bytes.length == 0) || offset < 0 || dateLen <= 0 || offset >= bytes.length || bytes.length - offset < dateLen) {
            return null;
        }
        byte[] bArr = new byte[dateLen];
        System.arraycopy(bytes, offset, bArr, 0, dateLen);
        try {
            Charset charsetForName = Charset.forName(CHARSET);
            o.b(charsetForName, "Charset.forName(CHARSET)");
            return new String(bArr, charsetForName);
        } catch (UnsupportedEncodingException e2) {
            Log.e(TAG, e2.getMessage(), e2);
            return null;
        }
    }

    public final String bytesToHexString(byte[] data) {
        o.g(data, "data");
        char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        char[] cArr2 = new char[data.length * 2];
        int length = data.length;
        for (int i2 = 0; i2 < length; i2++) {
            byte b2 = data[i2];
            int i3 = i2 * 2;
            cArr2[i3] = cArr[(b2 >>> 4) & 15];
            cArr2[i3 + 1] = cArr[b2 & BinaryMemcacheOpcodes.PREPEND];
        }
        return new String(cArr2);
    }

    public final byte getCheckSum(byte[] bytes, int maxIndex) {
        o.g(bytes, "bytes");
        int i2 = 0;
        for (int i3 = 0; i3 < maxIndex; i3++) {
            i2 += (byte) (((byte) DnsRecord.CLASS_ANY) & bytes[i3]);
        }
        return (byte) ((i2 % 256) & DnsRecord.CLASS_ANY);
    }
}
