Changed license to CC0
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / data / HexConverter.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.commons.data;
6
7 public class HexConverter {
8
9     static final String hexCharacters = "0123456789ABCDEF";
10
11     public static String byteArrayToHex(final byte[] bytes) {
12
13         if (bytes == null)
14             return null;
15
16         final StringBuilder result = new StringBuilder(2 * bytes.length);
17
18         for (final byte b : bytes)
19             result.append(hexCharacters.charAt((b & 0xF0) >> 4)).append(
20                     hexCharacters.charAt((b & 0x0F)));
21
22         return result.toString();
23     }
24
25 }