mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
Added a helper function and attribution to an existing one
This commit is contained in:
@@ -187,20 +187,29 @@ public class GB {
|
|||||||
return GBApplication.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);
|
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) {
|
public static String hexdump(byte[] buffer, int offset, int length) {
|
||||||
if (length == -1) {
|
if (length == -1) {
|
||||||
length = buffer.length - offset;
|
length = buffer.length - offset;
|
||||||
}
|
}
|
||||||
final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
|
||||||
char[] hexChars = new char[length * 2];
|
char[] hexChars = new char[length * 2];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
int v = buffer[i + offset] & 0xFF;
|
int v = buffer[i + offset] & 0xFF;
|
||||||
hexChars[i * 2] = hexArray[v >>> 4];
|
hexChars[i * 2] = HEX_CHARS[v >>> 4];
|
||||||
hexChars[i * 2 + 1] = hexArray[v & 0x0F];
|
hexChars[i * 2 + 1] = HEX_CHARS[v & 0x0F];
|
||||||
}
|
}
|
||||||
return new String(hexChars);
|
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) {
|
public static byte[] hexStringToByteArray(String s) {
|
||||||
int len = s.length();
|
int len = s.length();
|
||||||
byte[] data = new byte[len / 2];
|
byte[] data = new byte[len / 2];
|
||||||
|
Reference in New Issue
Block a user