Here you can find the source of bytesToHex(byte[] bytes, byte[] hex, int offset)
Parameter | Description |
---|---|
bytes | bytes to convert |
hex | the converted hex bytes |
offset | from where to start the conversion |
public static void bytesToHex(byte[] bytes, byte[] hex, int offset)
//package com.java2s; /**/*from w w w . ja v a2 s. c o m*/ * (C) 2011-2012 Alibaba Group Holding Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * */ public class Main { /** * Turns 16-byte stream into a human-readable 32-byte hex string This code * was copied from the PostgreSQL JDBC driver code (MD5Digest.java) * * @param bytes * bytes to convert * @param hex * the converted hex bytes * @param offset * from where to start the conversion */ public static void bytesToHex(byte[] bytes, byte[] hex, int offset) { final char lookup[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; int i, c, j, pos = offset; for (i = 0; i < 16; i++) { c = bytes[i] & 0xFF; j = c >> 4; hex[pos++] = (byte) lookup[j]; j = (c & 0xF); hex[pos++] = (byte) lookup[j]; } } }