Java Hex Calculate toHexString(byte[] v)

Here you can find the source of toHexString(byte[] v)

Description

Convert an array of bytes to a hex string.

License

LGPL

Parameter

Parameter Description
v a parameter

Declaration

public static String toHexString(byte[] v) 

Method Source Code

//package com.java2s;
/*//from  w  w w .  j ava2s  .co m
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

public class Main {
    /**
     * Convert an array of bytes to a hex string.
     *
     * @param v
     * @return
     */
    public static String toHexString(byte[] v) {
        final String HEX_DIGITS = "0123456789abcdef";
        StringBuffer sb = new StringBuffer(v.length * 2);
        for (int i = 0; i < v.length; i++) {
            int b = v[i] & 0xFF;
            sb.append(HEX_DIGITS.charAt(b >>> 4)).append(
                    HEX_DIGITS.charAt(b & 0xF));
        }
        return sb.toString();
    }
}

Related

  1. toHexString(byte[] paramArrayOfByte)
  2. toHexString(byte[] paramArrayOfByte, String paramString, boolean paramBoolean)
  3. toHexString(byte[] raw)
  4. toHexString(byte[] raw)
  5. toHexString(byte[] src)
  6. toHexString(byte[] v)
  7. toHexString(byte[] val)
  8. toHexString(byte[] value)
  9. toHexString(byte[] value)