Here you can find the source of toHexString(byte b)
b
as hex string (e.g. 0xd3
will return "d3"
).
public static String toHexString(byte b)
//package com.java2s; //License from project: Mozilla Public License public class Main { /** @return The value of <code>b</code> as hex string * (e.g. <code>0xd3</code> will return <code>"d3"</code>). */ public static String toHexString(byte b) { StringBuffer sb = new StringBuffer("00"); sb.append(Integer.toHexString(b)); return sb.substring(sb.length() - 2); }//from w ww .j av a2 s . co m /** @return The value of <code>i</code> as hex string * (e.g. <code>0xd3</code> will return <code>"d3"</code>). */ public static String toHexString(int i) { StringBuffer sb = new StringBuffer("00000000"); sb.append(Integer.toHexString(i)); return sb.substring(sb.length() - 8); } /** @return The value of <code>i</code> as hex string * (e.g. <code>0xd3</code> will return <code>"d3"</code>). */ public static String toHexString(long l) { StringBuffer sb = new StringBuffer("0000000000000000"); sb.append(Long.toHexString(l)); return sb.substring(sb.length() - 16); } /** @return The value of <code>bytes</code> as hex string * with the lowest index left. * <code>bytes[0] = 0xab</code> and <code>bytes[1] = 0xcd</code> * will return <code>"abcd"</code>. */ public static String toHexString(byte[] bytes) { StringBuffer sb = new StringBuffer(bytes.length * 2); for (int iH = 0; iH < bytes.length; iH++) sb.append(toHexString(bytes[iH])); return sb.toString(); } }