Java Hex Calculate toHexString(byte[] b, int off, int len)

Here you can find the source of toHexString(byte[] b, int off, int len)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte[] b, int off, int len) 

Method Source Code

//package com.java2s;
/*/*ww  w  .j  ava2s .c  o  m*/
 * @(#)ArrayUtil.java  
 *
 * Copyright (c) 2003-2010 Werner Randelshofer
 * Hausmatt 10, Immensee, CH-6405, Switzerland
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Werner Randelshofer. For details see accompanying license terms. 
 */

public class Main {
    private final static char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
            'e', 'f' };

    public static String toHexString(byte[] b, int off, int len) {
        StringBuffer buf = new StringBuffer();
        int end = off + len;
        for (; off < end; off++) {
            buf.append(hexChars[(b[off] & 0xf0) >>> 4]);
            buf.append(hexChars[b[off] & 0x0f]);
        }
        return buf.toString();
    }

    public static String toHexString(byte[] b) {
        return toHexString(b, 0, b.length);
    }
}

Related

  1. toHexString(byte[] b)
  2. toHexString(byte[] b)
  3. toHexString(byte[] b)
  4. toHexString(byte[] b)
  5. toHexString(byte[] b)
  6. toHexString(byte[] b, int off, int len)
  7. toHexString(byte[] ba)
  8. toHexString(byte[] ba)
  9. toHexString(byte[] ba, int offset, int length)