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

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

Description

to Hex String

License

Apache License

Declaration

@Deprecated
    public static String toHexString(byte[] content, int len) 

Method Source Code

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

public class Main {
    private static String[] HEXS = new String[] { "0", "1", "2", "3", "4",
            "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };

    @Deprecated
    public static String toHexString(byte[] content, int len) {
        if (content == null || content.length == 0) {
            return "";
        }/*  www.  j a va 2  s.  com*/
        if (len > content.length) {
            len = content.length;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            int c = content[i];
            c &= 0xFF;
            sb.append(' ').append(HEXS[c / 16]).append(HEXS[c % 16]);
        }
        sb.deleteCharAt(0);
        return sb.toString();
    }

    @Deprecated
    public static String toHexString(byte[] content) {
        if (content == null) {
            return "";
        }
        return toHexString(content, content.length);
    }
}

Related

  1. toHexString(byte[] bytes, boolean addPrefix)
  2. toHexString(byte[] bytes, int offset, int len, int max)
  3. toHexString(byte[] bytes, String separator, boolean upperCase)
  4. toHexString(byte[] coded)
  5. toHexString(byte[] color)
  6. toHexString(byte[] data)
  7. toHexString(byte[] data)
  8. toHexString(byte[] data)
  9. toHexString(byte[] data)