Refactored generic byte-related code out of AdRecordsUtil

This commit is contained in:
Alexandros Schillings
2014-03-10 19:38:35 +00:00
parent 0400f11f59
commit 103df3e66e
6 changed files with 38 additions and 34 deletions
@@ -0,0 +1,28 @@
package uk.co.alt236.btlescan.util;
public class ByteUtils {
static final String HEXES = "0123456789ABCDEF";
public static String byteArrayToHexString(final byte[] array){
final StringBuffer sb = new StringBuffer();
boolean firstEntry = true;
sb.append('[');
for ( final byte b : array ) {
if(!firstEntry){
sb.append(", ");
}
sb.append(HEXES.charAt((b & 0xF0) >> 4));
sb.append(HEXES.charAt((b & 0x0F)));
firstEntry = false;
}
sb.append(']');
return sb.toString();
}
public static int convertByteToInt(byte bite){
return Integer.valueOf(bite & 0xFF);
}
}