Here you can find the source of toHex(byte[] data, int off, int len)
public static String toHex(byte[] data, int off, int len)
//package com.java2s; /*/*from w ww . j ava 2 s. co m*/ * $Id$ * * Copyright (c) 2007, Dmitri Trounine. * All rights reserved. * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. */ public class Main { public static String toHex(byte[] data, int off, int len) { StringBuffer s = new StringBuffer(); for (int i = off; i < off + len; i++) { if (i > off) { s.append(' '); } s.append(toHex(0x000000ff & data[i])); } return s.toString(); } public static String toHex(int x) { StringBuffer s = new StringBuffer(); s.append("0x"); if (x < 16) { s.append('0'); } s.append(Integer.toHexString(0x000000ff & x)); return s.toString(); } }