Java Base Encode toBase16(int[] arr)

Here you can find the source of toBase16(int[] arr)

Description

to Base

License

Apache License

Declaration

public static String toBase16(int[] arr) 

Method Source Code

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

public class Main {
    public static String toBase16(int[] arr) {
        return toBase16(arr, ",");
    }//w  w  w.jav a  2 s. c  om

    public static String toBase16(int[] arr, String delimiter) {

        if (arr == null) {
            return "";
        }

        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < arr.length; i++) {
            sb.append(toBase16(arr[i]));

            if (i < arr.length - 1) {
                sb.append(delimiter);
            }
        }

        return sb.toString();
    }

    public static String toBase16(int b) {

        if (b > 0xff) {
            throw new IllegalArgumentException(String.format("Input value [%1$s] is larger than a byte", b));
        }

        if (b < 0x10) {
            return "0x0" + Integer.toHexString(b);
        } else {
            return "0x" + Integer.toHexString(b);
        }
    }

    /**
     * Converts an int array to string.  
     * Note: this method does not validate that int values map
     * to valid characters
     * 
     * @param arr
     * @return
     */
    public static String toString(int[] arr) {

        if (arr == null) {
            return "";
        }

        StringBuffer sb = new StringBuffer();

        for (int anArr : arr) {
            sb.append((char) anArr);
        }

        return sb.toString();
    }
}

Related

  1. toBase10(final String base62)
  2. toBase10(int[] arr)
  3. toBase10(int[] arr)
  4. toBase10SuffixedString(long n)
  5. toBase16(byte[] data)
  6. ToBase16(StringBuilder str, byte[] data)
  7. toBase2(byte b)
  8. toBase26(int number)
  9. toBase2SuffixedString(long n)