Java Hex Calculate toHexString(byte[] data, int start, int len)

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

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte[] data, int start, int len) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 * Copyright (c) 2004-2011 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: //from  w  w w  .  ja  v a 2  s .  c om
 *
 *    Kohsuke Kawaguchi, Winston Prakash
 *     
 *
 *******************************************************************************/

public class Main {
    public static String toHexString(byte[] data, int start, int len) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < len; i++) {
            int b = data[start + i] & 0xFF;
            if (b < 16) {
                buf.append('0');
            }
            buf.append(Integer.toHexString(b));
        }
        return buf.toString();
    }

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

Related

  1. toHexString(byte[] data)
  2. toHexString(byte[] data, final int offset, final int count)
  3. toHexString(byte[] data, int maxLen)
  4. toHexString(byte[] data, int offset, int length)
  5. toHexString(byte[] data, int offset, int length)
  6. toHexString(byte[] data, int start, int length)
  7. toHexString(byte[] digest)
  8. toHexString(byte[] digest)
  9. toHexString(byte[] digest)