Here you can find the source of bytesToHexFormatted(byte[] bytes)
public static String bytesToHexFormatted(byte[] bytes)
//package com.java2s; /**/*from w w w .j av a 2s . c om*/ * Copyright (c) 2010-2015, openHAB.org 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 { final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); public static String bytesToHexFormatted(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; hexChars[j * 2] = hexArray[v >>> 4]; hexChars[j * 2 + 1] = hexArray[v & 0x0F]; } return new String(hexChars); } }