package com.RNRSA;

/**
 * 世联行 WorldUnion <br>
 * 项目名称：世联行:WorldUnionYZG <br>
 * 类注释：<br>
 * 作者：0210289 <br>
 * 创建时间：on 2019/4/15<br>
 * 邮箱：xiaofeng3@worldunion.com.cn<br>
 * 备注：<br>
 */
public class ConvertUtils {


    private ConvertUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    static final char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    /**
     * byteArr转hexString
     * <p>例如：</p>
     * bytes2HexString(new byte[] { 0, (byte) 0xa8 }) returns 00A8
     *
     * @param bytes 字节数组
     * @return 16进制大写字符串
     */
    public static String bytes2HexString(byte[] bytes) {
        if (bytes == null)
            return null;
        int len = bytes.length;
        if (len <= 0)
            return null;
        char[] ret = new char[len << 1];
        for (int i = 0, j = 0; i < len; i++) {
            ret[j++] = hexDigits[bytes[i] >>> 4 & 0x0f];
            ret[j++] = hexDigits[bytes[i] & 0x0f];
        }
        return new String(ret);
    }

}
