Here you can find the source of bytesToHex(byte[] binary)
Parameter | Description |
---|---|
binary | a parameter |
public static String bytesToHex(byte[] binary)
//package com.java2s; /*********************************************************************** * Copyright (c) 2015 by Regents of the University of Minnesota. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Apache License, Version 2.0 which * accompanies this distribution and is available at * http://www.opensource.org/licenses/apache2.0.php. * *************************************************************************/ public class Main { private static final byte[] HexLookupTable = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /**//from ww w .j av a 2 s .c o m * Convert binary array to a hex string. * @param binary * @return */ public static String bytesToHex(byte[] binary) { // Each byte is converted to two hex values byte[] hex = new byte[binary.length * 2]; for (int i = 0; i < binary.length; i++) { hex[2 * i] = HexLookupTable[(binary[i] & 0xFF) >>> 4]; hex[2 * i + 1] = HexLookupTable[binary[i] & 0xF]; } return new String(hex); } }