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

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

Description

to Hex String

License

Apache License

Declaration

public final static String toHexString(byte[] data, int maxLen) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2013 EMBL-EBI/*from  ww w.j  a v a2s .c o  m*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

public class Main {
    public final static String toHexString(byte[] data, int maxLen) {
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < data.length && i < maxLen; i++) {
            sb.append(String.format("0x%02x", data[i]));
            if (i < data.length - 1 && i < maxLen - 1)
                sb.append(" ");
        }

        sb.append("]");
        return sb.toString();
    }
}

Related

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