Java Hex Calculate toHexString(byte[] ba, int offset, int length)

Here you can find the source of toHexString(byte[] ba, int offset, int length)

Description

converts String to Hex String.

License

Open Source License

Parameter

Parameter Description
ba Description of Parameter
offset Description of Parameter
length Description of Parameter

Return

Description of the Returned Value

Declaration

public static String toHexString(byte[] ba, int offset, int length) 

Method Source Code

//package com.java2s;
/*//  w w w  . j ava 2  s.  c o m
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

public class Main {
    /** Field HEX_DIGITS */
    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
            'E', 'F' };

    /**
     *  converts String to Hex String. Example: niko ->6E696B6F
     *
     * @param  ba      Description of Parameter
     * @param  offset  Description of Parameter
     * @param  length  Description of Parameter
     * @return         Description of the Returned Value
     */
    public static String toHexString(byte[] ba, int offset, int length) {

        char[] buf;

        buf = new char[length * 2];

        for (int i = offset, j = 0, k; i < offset + length;) {
            k = ba[i++];
            buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F];
            buf[j++] = HEX_DIGITS[k & 0x0F];

        }

        return new String(buf);
    }
}

Related

  1. toHexString(byte[] b)
  2. toHexString(byte[] b, int off, int len)
  3. toHexString(byte[] b, int off, int len)
  4. toHexString(byte[] ba)
  5. toHexString(byte[] ba)
  6. toHexString(byte[] binary)
  7. toHexString(byte[] binaryData)
  8. toHexString(byte[] block)
  9. toHexString(byte[] buf)