Here you can find the source of byteToHexWithPrefix(final byte[] data)
Parameter | Description |
---|---|
data | to convert |
public static String byteToHexWithPrefix(final byte[] data)
//package com.java2s; //License from project: Apache License import java.util.Formatter; public class Main { /**/*from w ww. java 2s. c om*/ * Convert bytes to hex + 0x in front. * * @param data * to convert * @return hex string */ public static String byteToHexWithPrefix(final byte[] data) { return "0x" + byteToHex(data); } /** * Convert bytes to hex without (no 0x in front). * * @param data * to convert * @return hex strng */ public static String byteToHex(final byte[] data) { Formatter formatter = new Formatter(); for (byte b : data) { formatter.format("%02x", b); } String result = formatter.toString(); formatter.close(); return result; } }