Java Hex Calculate toHexString(byte[] binary)

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

Description

To hex string.

License

Open Source License

Parameter

Parameter Description
binary the byte array to convert

Return

the string the converted hex string

Declaration

public static String toHexString(byte[] binary) 

Method Source Code

//package com.java2s;
/*/*from w ww .ja va2 s.c  o  m*/
 * Copyright 2009 Jagornet Technologies, LLC.  All Rights Reserved.
 *
 * This software is the proprietary information of Jagornet Technologies, LLC. 
 * Use is subject to license terms.
 *
 */

public class Main {
    /**
     * To hex string.
     * 
     * @param binary the byte array to convert
     * 
     * @return the string the converted hex string
     */
    public static String toHexString(byte[] binary) {
        if (binary != null) {
            StringBuffer str = new StringBuffer(binary.length * 2);
            for (int i = 0; i < binary.length; i++) {
                int v = (binary[i] << 24) >>> 24;
                str.append((v < 0x10 ? "0" : "") + Integer.toHexString(v));
            }
            return str.toString();
        }
        return null;
    }
}

Related

  1. toHexString(byte[] b, int off, int len)
  2. toHexString(byte[] b, int off, int len)
  3. toHexString(byte[] ba)
  4. toHexString(byte[] ba)
  5. toHexString(byte[] ba, int offset, int length)
  6. toHexString(byte[] binaryData)
  7. toHexString(byte[] block)
  8. toHexString(byte[] buf)
  9. toHexString(byte[] buf)