Here you can find the source of convertBytesToString(byte[] value)
Parameter | Description |
---|---|
value | the byte array |
public static String convertBytesToString(byte[] value)
//package com.java2s; /*// www . ja v a2s. co m * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group */ public class Main { private static final char[] HEX = "0123456789abcdef".toCharArray(); /** * Convert a byte array to a hex encoded string. * * @param value * the byte array * @return the hex encoded string */ public static String convertBytesToString(byte[] value) { return convertBytesToString(value, value.length); } /** * Convert a byte array to a hex encoded string. * * @param value * the byte array * @param len * the number of bytes to encode * @return the hex encoded string */ public static String convertBytesToString(byte[] value, int len) { char[] buff = new char[len + len]; char[] hex = HEX; for (int i = 0; i < len; i++) { int c = value[i] & 0xff; buff[i + i] = hex[c >> 4]; buff[i + i + 1] = hex[c & 0xf]; } return new String(buff); } }