Java Hex Calculate toHex(final char[] dest, int destPos, final byte[] src, final int srcStart, final int srcLength)

Here you can find the source of toHex(final char[] dest, int destPos, final byte[] src, final int srcStart, final int srcLength)

Description

to Hex

License

Apache License

Declaration

public static final int toHex(final char[] dest, int destPos, final byte[] src, final int srcStart,
            final int srcLength) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/* ww  w.  j a v a2s .co m*/
     * All possible chars for representing a number as a String
     */
    final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
            'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };

    public static final int toHex(final char[] dest, int destPos, final byte[] src, final int srcStart,
            final int srcLength) {
        for (int i = 0; i < srcLength; i++) {
            int u = src[i] & 255;
            dest[destPos + 1] = digits[u & 0x0F];
            u >>>= 4;
            dest[destPos] = digits[u & 0x0F];
            destPos += 2;
        }
        return srcLength << 1;
    }
}

Related

  1. toHex(final byte[] data, final int startPos, final int length)
  2. toHex(final byte[] data, final String separator)
  3. toHex(final byte[] input)
  4. toHex(final byte[] value)
  5. toHex(final char a, final int halfbyte)
  6. toHex(final int i)
  7. toHex(final int value)
  8. toHex(final String input)
  9. toHex(int ch)