Annotation of java/classes/org/w3c/util/StringUtils.java, revision 1.2

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

Webmaster