Here you can find the source of toHexString(byte[] b, int off, int len)
Parameter | Description |
---|---|
b | The bytes to convert. |
public static String toHexString(byte[] b, int off, int len)
//package com.java2s; /*//from ww w . ja va 2 s . c om * Copyright (C) 2012 McEvoy Software Ltd * * 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/>. * */ public class Main { /** Hexadecimal digits. */ private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /** * Convert a byte array to a big-endian ordered hexadecimal string. * * @param b The bytes to convert. * @return A hexadecimal representation to <tt>b</tt>. */ public static String toHexString(byte[] b) { return toHexString(b, 0, b.length); } /** * Convert a byte array to a big-endian ordered hexadecimal string. * * @param b The bytes to convert. * @return A hexadecimal representation to <tt>b</tt>. */ public static String toHexString(byte[] b, int off, int len) { char[] buf = new char[len * 2]; for (int i = 0, j = 0, k; i < len;) { k = b[off + i++]; buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; buf[j++] = HEX_DIGITS[k & 0x0F]; } return new String(buf); } }