Java Hex Calculate toHex(final byte[] data)

Here you can find the source of toHex(final byte[] data)

Description

Convert byte array to hex string

License

Open Source License

Parameter

Parameter Description
data the data to convert

Return

a hex string, lower case, no delimiters

Declaration

public static String toHex(final byte[] data) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006, 2014 TH4 SYSTEMS GmbH and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   w w w  .  j  av a2s  .com*/
 *     TH4 SYSTEMS GmbH - initial API and implementation
 *     IBH SYSTEMS GmbH - documentation, add toHex
 *******************************************************************************/

public class Main {
    /**
     * Convert byte array to hex string
     *
     * @param data
     *            the data to convert
     * @return a hex string, lower case, no delimiters
     */
    public static String toHex(final byte[] data) {
        if (data == null) {
            return null;
        }

        final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < data.length; i++) {
            sb.append(String.format("%02x", data[i]));
        }
        return sb.toString();
    }
}

Related

  1. toHex(final byte[] bytes)
  2. toHex(final byte[] bytes)
  3. tohex(final byte[] bytes)
  4. toHex(final byte[] bytes, final int offset, final int count)
  5. toHex(final byte[] data)
  6. toHex(final byte[] data)
  7. toHex(final byte[] data, final int startPos, final int length)
  8. toHex(final byte[] data, final String separator)
  9. toHex(final byte[] input)