Here you can find the source of toHexString(byte[] bytes)
public static String toHexString(byte[] bytes)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004 Actuate Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w. java 2 s . c o m * Actuate Corporation - initial API and implementation *******************************************************************************/ public class Main { public static String toHexString(byte[] bytes) { StringBuffer result = new StringBuffer(); int length = 0; for (int i = 0; i < bytes.length; i++) { result.append(toHexString(bytes[i])); length += 2; if (length > 80) { result.append("\n"); length = 0; } } return result.toString(); } private static String toHexString(byte b) { String result; result = Integer.toHexString(toInt(b)); if (result.length() == 1) { result = "0" + result; } return result; } public static String toHexString(int c) { final String[] padding = { "0", "00", "000" }; String result = Integer.toHexString(c); if (result.length() < 4) { result = padding[3 - result.length()] + result; } return result; } private static int toInt(byte b) { return 0xff & b; } }