Java Byte Array to Hex String bytesToHexString(final byte[] bytes)

Here you can find the source of bytesToHexString(final byte[] bytes)

Description

bytes To Hex String

License

Apache License

Declaration

public static String bytesToHexString(final byte[] bytes) 

Method Source Code

//package com.java2s;
/*/*from w  w w  .  j  a v a 2 s.c o  m*/
 * Copyright 2013-2016 Netherlands Forensic Institute
 *
 * 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 {
    final private static char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();

    public static String bytesToHexString(final byte[] bytes) {
        checkNotNull(bytes, "bytes");
        final char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            final int v = bytes[j] & 0xFF;
            hexChars[j * 2] = HEX_ARRAY[v >>> 4];
            hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
        }
        return new String(hexChars);
    }

    public static <T> T checkNotNull(final T argument, final String name) {
        if (argument == null) {
            throw new IllegalArgumentException("Argument " + name + " may not be null.");
        }
        return argument;
    }
}

Related

  1. bytesToHexString(byte[] input)
  2. bytesToHexString(byte[] mpi)
  3. bytesToHexString(byte[] src)
  4. bytesToHexString(byte[] src)
  5. bytesToHexString(final byte[] bytes)
  6. bytesToHexString(final byte[] bytes)
  7. bytesToHexString(final byte[] bytes)
  8. bytesToHexString(final byte[] bytes)
  9. bytesToHexString(final byte[] bytes, int start, int end)