package com.hboxs.serialport.util;

public class AsciiUtils {

    /**
     * Ascii字节数组转16进制字符串
     * @param data Ascii字节数组
     * @return 16进制字符串
     */
    public static String asciiByteArray2HexStr(byte[] data) {
        StringBuilder stringBuilder = new StringBuilder();

        if (data != null && data.length > 0) {
            for (byte b : data) {
                stringBuilder.append(Integer.toHexString(Integer.parseInt((char) (0xFF & b) + "", 16)).toUpperCase());
            }
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(asciiByteArray2HexStr(new byte[]{0x30, 0x31}));
    }
}
