01: // StringUtils.java
02: // $Id: StringUtils.java,v 1.2 2000/08/16 21:37:58 ylafon Exp $
03: // (c) COPYRIGHT MIT, INRIA and Keio, 1999.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.util;
07:
08: public class StringUtils {
09: /**
10: * to hex converter
11: */
12: private static final char[] toHex = { '0', '1', '2', '3', '4', '5',
13: '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
14:
15: /**
16: * convert an array of bytes to an hexadecimal string
17: * @param an array of bytes
18: * @return a string
19: */
20:
21: public static String toHexString(byte b[]) {
22: int pos = 0;
23: char[] c = new char[b.length * 2];
24: for (int i = 0; i < b.length; i++) {
25: c[pos++] = toHex[(b[i] >> 4) & 0x0F];
26: c[pos++] = toHex[b[i] & 0x0f];
27: }
28: return new String(c);
29: }
30: }
|