Here you can find the source of toHexStr(final ByteBuffer data)
Parameter | Description |
---|---|
data | The data to convert |
public static String toHexStr(final ByteBuffer data)
//package com.java2s; // Licensed under LGPLv3 - http://www.gnu.org/licenses/lgpl-3.0.txt import java.nio.ByteBuffer; public class Main { /**/* w ww . j a v a 2 s .co m*/ * Convert the bytes to a hex string. * * @param data The data to convert * @return The hex string */ public static String toHexStr(final int[] data) { final StringBuilder sysex = new StringBuilder(); for (final int d : data) sysex.append(toHexStr(d)).append(' '); return sysex.toString(); } /** * Convert the bytes to a hex string. Rewinds the buffer and adds the bytes from the beginning * till the capacity. * * @param data The data to convert * @return The hex string */ public static String toHexStr(final ByteBuffer data) { final StringBuilder sysex = new StringBuilder(); while (data.position() < data.limit()) sysex.append(toHexStr(Byte.toUnsignedInt(data.get()))).append(' '); return sysex.toString(); } /** * Convert the bytes to a hex string * * @param data The data to convert * @return The hex string */ public static String toHexStr(final byte[] data) { final StringBuilder sysex = new StringBuilder(); for (final byte d : data) sysex.append(toHexStr(Byte.toUnsignedInt(d))).append(' '); return sysex.toString(); } /** * Convert the byte to a hex string * * @param number The value to convert * @return The hex string */ public static String toHexStr(final int number) { return String.format("%02X", Integer.valueOf(number)); } }