Java Byte Array to Hex bytesToHex(byte[] bytes, byte[] hex, int offset)

Here you can find the source of bytesToHex(byte[] bytes, byte[] hex, int offset)

Description

Turns 16-byte stream into a human-readable 32-byte hex string This code was copied from the PostgreSQL JDBC driver code (MD5Digest.java)

License

Open Source License

Parameter

Parameter Description
bytes bytes to convert
hex the converted hex bytes
offset from where to start the conversion

Declaration

public static void bytesToHex(byte[] bytes, byte[] hex, int offset) 

Method Source Code

//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];
        }
    }
}

Related

  1. bytesToHex(byte[] bytes)
  2. bytesToHex(byte[] bytes)
  3. bytesToHex(byte[] bytes)
  4. bytesToHex(byte[] bytes)
  5. bytesToHex(byte[] bytes)
  6. bytesToHex(byte[] bytes, int groupSize)
  7. bytesToHex(byte[] bytes, int size, char delim)
  8. bytesToHex(byte[] data)
  9. bytesToHex(byte[] data)