Here you can find the source of toHex(byte[] bytes)
Parameter | Description |
---|---|
bytes | Source byte array |
public static String toHex(byte[] bytes)
//package com.java2s; /*//from w w w .j av a 2s.co m * WireSpider * * Copyright (c) 2015 kazyx * * This software is released under the MIT License. * http://opensource.org/licenses/mit-license.php */ public class Main { private static final char[] HEX_SOURCE = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * Convert byte array to HEX format. * * @param bytes Source byte array * @return HEX format. */ public static String toHex(byte[] bytes) { StringBuilder sb = new StringBuilder(); sb.append("0x"); for (byte b : bytes) { int v = b & 0xFF; sb.append(HEX_SOURCE[v >>> 4]).append(HEX_SOURCE[v & 0x0F]); } return sb.toString(); } }