Java Hex Calculate toHexString(final byte[] data)

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

Description

Converts an array of bytes into a hexadecimal representation.

License

Open Source License

Parameter

Parameter Description
data a parameter

Declaration

public static String toHexString(final byte[] data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w ww .jav  a  2s .c o  m
     * Converts an array of bytes into a hexadecimal representation. Not
     * particularly efficient.
     * @param data
     * @return
     */
    public static String toHexString(final byte[] data) {
        // TODO: Write own code for conversion
        final StringBuilder result = new StringBuilder();
        for (int i = 0; i < data.length; ++i)
            result.append(Integer.toHexString((data[i] & 0xFF) | 0x100).substring(1, 3));

        return result.toString();
    }
}

Related

  1. toHexString(final byte[] bytes)
  2. toHexString(final byte[] bytes)
  3. toHexString(final byte[] bytes)
  4. toHexString(final byte[] bytes)
  5. toHexString(final byte[] data)
  6. toHexString(final byte[] data)
  7. toHexString(final byte[] fieldData)
  8. toHexString(final byte[] raw)
  9. toHexString(final int i)