Here you can find the source of bytesToHexString(byte[] bytes)
public static String bytesToHexString(byte[] bytes)
//package com.java2s; /*// ww w.j a va 2s . co m * Copyright (c) 2015 Yoyodyne, Inc. and others. 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 */ public class Main { public static String bytesToHexString(byte[] bytes) { if (bytes == null) { return "null"; } String ret = ""; StringBuffer buf = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { if (i > 0) { ret += ":"; } short u8byte = (short) (bytes[i] & 0xff); String tmp = Integer.toHexString(u8byte); if (tmp.length() == 1) { buf.append("0"); } buf.append(tmp); } ret = buf.toString(); return ret; } }