Here you can find the source of bytesToHex(final byte[] bytes)
public static String bytesToHex(final byte[] bytes)
//package com.java2s; /*/*from w w w. j a v a 2s.c o m*/ * Copyright Nathan Jones 2013 * * This file is part of Juzidian. * * Juzidian is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Juzidian is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Juzidian. If not, see <http://www.gnu.org/licenses/>. */ public class Main { private static final char[] HEX_CHARS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * Create a hexadecimal string representation of the given byte array. */ public static String bytesToHex(final byte[] bytes) { final StringBuilder sb = new StringBuilder(); for (final byte b : bytes) { sb.append(byteToHex(b)); } return sb.toString(); } private static String byteToHex(final byte b) { final char byteHexChar1 = HEX_CHARS[(b & 0xf0) >> 4]; final char byteHexChar2 = HEX_CHARS[b & 0x0f]; return byteHexChar1 + "" + byteHexChar2; } }