// StringUtils.java
// $Id: StringUtils.java,v 1.4 2012/06/26 09:47:28 ylafon Exp $
// (c) COPYRIGHT MIT, INRIA and Keio, 1999.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.util;
public class StringUtils {
/**
* to hex converter
*/
private static final char[] toHex = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f'};
/**
* convert an array of bytes to an hexadecimal string
*
* @param b an array of bytes
* @return a string
*/
public static String toHexString(byte b[]) {
int pos = 0;
char[] c = new char[b.length * 2];
for (byte bi : b) {
c[pos++] = toHex[(bi >> 4) & 0x0F];
c[pos++] = toHex[bi & 0x0f];
}
return new String(c);
}
}
Webmaster