Here you can find the source of bytesToHex(byte[] a)
public static String bytesToHex(byte[] a)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from ww w . j a v a 2 s.c o m * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ public class Main { public static String bytesToHex(byte[] a) { if (a == null || a.length == 0) { return null; } StringBuffer buf = new StringBuffer(a.length * 2); int hi, lo; for (int i = 0; i < a.length; i++) { lo = (a[i]) & 0xff; hi = (lo >> 4); lo = lo & 0x0f; buf.append(Integer.toHexString(hi)); buf.append(Integer.toHexString(lo)); } return buf.toString(); } }