Here you can find the source of bytesToHexString(byte[] in, int length)
public static char[] bytesToHexString(byte[] in, int length)
//package com.java2s; /**//w w w . j ava 2 s .c o m * Copyright (C) 2006-2008 Werner Dittmann * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. * * Authors: Werner Dittmann <Werner.Dittmann@t-online.de> */ public class Main { private static final char[] hex = "0123456789abcdef".toCharArray(); public static char[] bytesToHexString(byte[] in, int length) { if (length > in.length) return null; char[] out = new char[length * 2]; for (int i = 0; i < length; i++) { byte b = in[i]; out[i * 2] = hex[(b >>> 4) & 0xf]; out[i * 2 + 1] = hex[b & 0xf]; } return out; } }