--- /dev/null
+package eu.svjatoslav.commons.data;
+
+public class HexConverter {
+
+ static final String hexCodes = "0123456789ABCDEF";
+
+ public static String byteArrayToHex(final byte[] raw) {
+
+ if (raw == null)
+ return null;
+
+ final StringBuilder result = new StringBuilder(2 * raw.length);
+
+ for (final byte b : raw)
+ result.append(hexCodes.charAt((b & 0xF0) >> 4)).append(
+ hexCodes.charAt((b & 0x0F)));
+
+ return result.toString();
+ }
+
+}
--- /dev/null
+package eu.svjatoslav.commons.data;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class HexConverterTest {
+
+ @Test
+ public void test() {
+
+ final String string = HexConverter.byteArrayToHex(new byte[] { 1, 2,
+ (byte) 255 });
+
+ assertEquals("0102FF", string);
+
+ }
+}