Here you can find the source of bytesToHexChars(byte[] bytes)
public static char[] bytesToHexChars(byte[] bytes)
//package com.java2s; /*//from w w w .j a va2 s . c o m GRANITE DATA SERVICES Copyright (C) 2011 GRANITE DATA SERVICES S.A.S. This file is part of Granite Data Services. Granite Data Services is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Granite Data Services 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, see <http://www.gnu.org/licenses/>. */ public class Main { private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray(); public static char[] bytesToHexChars(byte[] bytes) { return bytesToHexChars(bytes, new char[bytes.length * 2], 0); } public static char[] bytesToHexChars(byte[] bytes, char[] chars, int off) { if (chars.length - off < bytes.length * 2) throw new IllegalArgumentException("Unsufficient capacity in 'chars' parameter"); for (int i = off, j = 0; i < bytes.length;) { int b = bytes[i++] & 0xFF; chars[j++] = HEX_CHARS[b >> 4]; chars[j++] = HEX_CHARS[b & 0x0F]; } return chars; } }