Here you can find the source of bytesToHexString(byte[] bytes)
public static String bytesToHexString(byte[] bytes)
//package com.java2s; /******************************************************************************* * Copyright 2007-2013 See AUTHORS file.//from w w w. java2s . com * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * 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 { /** A table of hex digits */ private static final char[] hexDigit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String bytesToHexString(byte[] bytes) { char[] buf = new char[bytes.length * 2]; int radix = 1 << 4; int mask = radix - 1; for (int i = 0; i < bytes.length; i++) { buf[2 * i] = hexDigit[(bytes[i] >>> 4) & mask]; buf[2 * i + 1] = hexDigit[bytes[i] & mask]; } return new String(buf); } }