new function: foHex() v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 04 Jan 2014 19:38:51 +0100
branchv_0
changeset 127d63de8a0a61f
parent 126 2357a9d08660
child 128 67f5ff139da0
new function: foHex()
java/sql-dk/src/info/globalcode/sql/dk/Functions.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/Functions.java	Sat Jan 04 19:38:20 2014 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/Functions.java	Sat Jan 04 19:38:51 2014 +0100
     1.3 @@ -141,4 +141,15 @@
     1.4  		Arrays.fill(array, ch);
     1.5  		return new String(array);
     1.6  	}
     1.7 +	private final static char[] HEX_ALPHABET = "0123456789abcdef".toCharArray();
     1.8 +
     1.9 +	public static String toHex(byte[] bytes) {
    1.10 +		char[] hexChars = new char[bytes.length * 2];
    1.11 +		for (int j = 0; j < bytes.length; j++) {
    1.12 +			int v = bytes[j] & 0xFF;
    1.13 +			hexChars[j * 2] = HEX_ALPHABET[v >>> 4];
    1.14 +			hexChars[j * 2 + 1] = HEX_ALPHABET[v & 0x0F];
    1.15 +		}
    1.16 +		return new String(hexChars);
    1.17 +	}
    1.18  }