56 lines
1.9 KiB
Java
56 lines
1.9 KiB
Java
package com.google.android.gms.common.util;
|
|
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class Hex {
|
|
private static final char[] zza = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
|
private static final char[] zzb = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
|
public static String bytesToStringLowercase(byte[] bArr) {
|
|
int length = bArr.length;
|
|
char[] cArr = new char[length + length];
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (i2 < bArr.length) {
|
|
byte b = bArr[i2];
|
|
char[] cArr2 = zzb;
|
|
cArr[i] = cArr2[(b & UnsignedBytes.MAX_VALUE) >>> 4];
|
|
cArr[i + 1] = cArr2[b & 15];
|
|
i2++;
|
|
i += 2;
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
|
|
public static String bytesToStringUppercase(byte[] bArr) {
|
|
return bytesToStringUppercase(bArr, false);
|
|
}
|
|
|
|
public static byte[] stringToBytes(String str) throws IllegalArgumentException {
|
|
int length = str.length();
|
|
if (length % 2 != 0) {
|
|
throw new IllegalArgumentException("Hex string has odd number of characters");
|
|
}
|
|
byte[] bArr = new byte[length / 2];
|
|
int i = 0;
|
|
while (i < length) {
|
|
int i2 = i + 2;
|
|
bArr[i / 2] = (byte) Integer.parseInt(str.substring(i, i2), 16);
|
|
i = i2;
|
|
}
|
|
return bArr;
|
|
}
|
|
|
|
public static String bytesToStringUppercase(byte[] bArr, boolean z) {
|
|
int length = bArr.length;
|
|
StringBuilder sb = new StringBuilder(length + length);
|
|
for (int i = 0; i < length && (!z || i != length - 1 || (bArr[i] & UnsignedBytes.MAX_VALUE) != 0); i++) {
|
|
char[] cArr = zza;
|
|
sb.append(cArr[(bArr[i] & 240) >>> 4]);
|
|
sb.append(cArr[bArr[i] & 15]);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|