Here you can find the source of toHex(byte[] buffer)
Parameter | Description |
---|---|
buffer | containing the bytes to convert |
public static char[] toHex(byte[] buffer)
//package com.java2s; public class Main { private static final char[] HEX = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; /**/*www . j ava 2 s.c o m*/ * Render a byte array into a string of hexadecimal numbers. * @param buffer containing the bytes to convert * @return a character array of length 2 with hexadecimal digits representing the bytes. */ public static char[] toHex(byte[] buffer) { char[] result = new char[buffer.length * 2]; for (int i = 0; i < buffer.length; i++) { result[i << 1] = HEX[(buffer[i] & 0xF0) >>> 4]; result[(i << 1) + 1] = HEX[buffer[i] & 0x0F]; } return result; } }