1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Added a helper function and attribution to an existing one

This commit is contained in:
TaaviE 2020-10-02 02:02:58 +03:00
parent e496aa8f7b
commit 77a6e6107a

View File

@ -187,20 +187,29 @@ public class GB {
return GBApplication.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
}
public static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
public static String hexdump(byte[] buffer, int offset, int length) {
if (length == -1) {
length = buffer.length - offset;
}
final char[] hexArray = "0123456789ABCDEF".toCharArray();
char[] hexChars = new char[length * 2];
for (int i = 0; i < length; i++) {
int v = buffer[i + offset] & 0xFF;
hexChars[i * 2] = hexArray[v >>> 4];
hexChars[i * 2 + 1] = hexArray[v & 0x0F];
hexChars[i * 2] = HEX_CHARS[v >>> 4];
hexChars[i * 2 + 1] = HEX_CHARS[v & 0x0F];
}
return new String(hexChars);
}
public static String hexdump(byte[] buffer) {
return hexdump(buffer, 0, buffer.length);
}
/**
* https://stackoverflow.com/a/140861/4636860
*/
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];