Java Byte to Hex String byteToHexString(byte[] bytes, int start, int end)

Here you can find the source of byteToHexString(byte[] bytes, int start, int end)

Description

Given an array of bytes it will convert the bytes to a hex string representation of the bytes

License

Apache License

Parameter

Parameter Description
bytes a parameter
start start index, inclusively
end end index, exclusively

Return

hex string representation of the byte array

Declaration

public static String byteToHexString(byte[] bytes, int start, int end) 

Method Source Code

//package com.java2s;
/*/*from ww  w  .  ja  va  2  s  .  com*/
 *  * Copyright 2016 Skymind, Inc.
 *  *
 *  *    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 {
    /**
     * Given an array of bytes it will convert the bytes to a hex string
     * representation of the bytes
     * @param bytes
     * @param start start index, inclusively
     * @param end end index, exclusively
     * @return hex string representation of the byte array
     */
    public static String byteToHexString(byte[] bytes, int start, int end) {
        if (bytes == null) {
            throw new IllegalArgumentException("bytes == null");
        }
        StringBuilder s = new StringBuilder();
        for (int i = start; i < end; i++) {
            s.append(String.format("%02x", bytes[i]));
        }
        return s.toString();
    }

    /** Same as byteToHexString(bytes, 0, bytes.length). */
    public static String byteToHexString(byte bytes[]) {
        return byteToHexString(bytes, 0, bytes.length);
    }
}

Related

  1. byteToHexString(byte value)
  2. byteToHexString(byte value)
  3. byteToHexString(byte[] b)
  4. byteToHexString(byte[] b)
  5. byteToHexString(byte[] bytes)
  6. byteToHexString(byte[] bytes, int start, int end)
  7. byteToHexString(byte[] data)
  8. byteToHexString(final byte b)
  9. byteToHexString(final byte b)