Java Byte Array to Hex String bytesToHexStringLine(byte[] bs, int lineLength)

Here you can find the source of bytesToHexStringLine(byte[] bs, int lineLength)

Description

bytes To Hex String Line

License

Apache License

Declaration

public static String bytesToHexStringLine(byte[] bs, int lineLength) 

Method Source Code

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

public class Main {
    private static final char[] hex = "0123456789ABCDEF".toCharArray();

    public static String bytesToHexStringLine(byte[] bs, int lineLength) {
        if (bs == null || bs.length == 0) {
            return "";
        }/*ww w  .  j  av a 2 s . c o  m*/
        StringBuffer str = new StringBuffer(bs.length * 4);
        for (int i = 0; i < bs.length; i++) {
            str.append(hex[(bs[i] >> 4) & 0x0f]);
            str.append(hex[bs[i] & 0x0f]);
            if (i > 0 && i % lineLength == lineLength - 1) {
                str.append("\r\n");
            } else {
                str.append(" ");
            }
        }
        return str.toString();
    }
}

Related

  1. bytesToHexString(final byte[] bytes)
  2. bytesToHexString(final byte[] bytes)
  3. bytesToHexString(final byte[] bytes)
  4. bytesToHexString(final byte[] bytes, int start, int end)
  5. bytesToHexString(final byte[] data)
  6. bytesToHexStringWithSpace(byte[] bytes)