Here you can find the source of bytes_to_str(byte[] data)
public static String bytes_to_str(byte[] data)
//package com.java2s; /*/* w w w.j av a 2 s . c o m*/ * Copyright (c) 2001-2003 Regents of the University of California. * All rights reserved. * * See the file LICENSE included in this distribution for details. */ public class Main { private static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String bytes_to_str(byte[] data) { return bytes_to_str(data, 0, data.length, false); } public static String bytes_to_str(byte[] data, int offset, int length) { return bytes_to_str(data, offset, length, false); } public static String bytes_to_str(byte[] data, int offset, int length, boolean pretty) { StringBuffer sbuf = new StringBuffer(length * 2); bytes_to_sbuf(data, offset, length, pretty, sbuf); return sbuf.toString(); } public static void bytes_to_sbuf(byte[] data, int offset, int length, StringBuffer buf) { bytes_to_sbuf(data, offset, length, false, buf); } public static void bytes_to_sbuf(byte[] data, int offset, int length, boolean pretty, StringBuffer buf) { int size = 2 * length; size += (size / 8) + (size / 64); int low_mask = 0x0f; int high_mask = 0xf0; byte b; int j = 0; for (int i = offset; i < (offset + length); ++i) { b = data[i]; buf.append(digits[(high_mask & b) >> 4]); buf.append(digits[(low_mask & b)]); if (pretty) { if (j % 4 == 3) buf.append(' '); if (j % 32 == 31) buf.append('\n'); } ++j; } } }