Here you can find the source of printHex(byte[] field, int start, int len)
public static String printHex(byte[] field, int start, int len)
//package com.java2s; /*//from ww w . ja v a 2 s.c o m * Copyright 2005-2008 by beck et al. projects GmbH, Munich * Copyright 2009 by Kappich Systemberatung, Aachen * * This file is part of de.bsvrz.sys.funclib.losb. * * de.bsvrz.sys.funclib.losb is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * de.bsvrz.sys.funclib.losb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with de.bsvrz.sys.funclib.losb. If not, see <http://www.gnu.org/licenses/>. * Contact Information: * Kappich Systemberatung * Martin-Luther-Stra?e 14 * 52062 Aachen, Germany * phone: +49 241 4090 436 * mail: <info@kappich.de> */ public class Main { public static String printHex(byte[] field, int start, int len) { StringBuffer sb = new StringBuffer((field.length * 3) - 1); int stop = field.length < len ? field.length : (start + len); for (int i = start; i < stop; i++) { int b = (field[i] >> 4) & 0x0000000F; if (b < 10) { sb.append(b); } else { sb.append((char) ('A' + b - 10)); } b = field[i] & 0x0000000F; if (b < 10) { sb.append(b); } else { sb.append((char) ('A' + b - 10)); } if (i + 1 < stop) sb.append(" "); } return sb.toString(); } public static String printHex(byte[] field) { return printHex(field, 0, field.length); } }