Here you can find the source of toHexString(byte[] b)
public static String toHexString(byte[] b)
//package com.java2s; /*/* w w w. j a va2 s . c o m*/ * Copyright 2005 MBARI * * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1 * (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.gnu.org/copyleft/lesser.html * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Format a byte array as a hexadecimal string. For example * <pre> * byte[] bytes = new byte[]{(byte)0x12, (byte)0x0F, (byte)0xF0}; * String hex = NumberUtilities.toHexString(bytes); // 120ff0 *</pre> * */ public static String toHexString(byte[] b) { if (b == null) { return "null"; } StringBuffer ret = new StringBuffer(b.length); for (int i = 0; i < b.length; i++) { String hex = Integer.toHexString(0x0100 + (b[i] & 0x00FF)).substring(1); ret.append((hex.length() < 2 ? "0" : "") + hex); } return ret.toString(); } }