Here you can find the source of bytesToHexString(final byte[] bytes, int start, int end)
Parameter | Description |
---|---|
bytes | the given bytes array to convert. |
start | the given start index, inclusively. |
end | the given end index, exclusively. |
public static String bytesToHexString(final byte[] bytes, int start, int end)
//package com.java2s; /***************************************************************** Copyright 2006 by Dung Nguyen (dungnguyen@truthinet.com) //from w w w . j a v a 2 s .c om Licensed under the iNet Solutions Corp.,; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.truthinet.com/licenses 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 { /** the empty string. */ public static final String EMPTY_STRING = ""; /** * Returns the string representation of the given {@code bytes}. * * @param bytes the given bytes array to convert. * @param start the given start index, inclusively. * @param end the given end index, exclusively. * @return hex string representation as {@code bytes}. */ public static String bytesToHexString(final byte[] bytes, int start, int end) { if (bytes == null || bytes.length == 0) { return EMPTY_STRING; } final StringBuilder builder = new StringBuilder((end - start) << 1); for (int index = start; index < end; index++) { builder.append(String.format("%02x", bytes[index])); } return builder.toString(); } /** * Returns the string representation of the given {@code bytes}. * * @param bytes the given bytes array to convert. * @return hex string representation as {@code bytes}. */ public static String bytesToHexString(final byte[] bytes) { return bytesToHexString(bytes, 0, bytes.length); } }