byte[ ]數組 轉換成16進制 字符數組

轉成16進制字符串



byte[] bs = new byte[6];
        buff.get(bs);
        sAddress = ByteUtilities.asHex(bs);


byte[ ]數組 轉換成16進制 字符數組 

public String[] bytesToHexString(byte[] byteSrc)
    {
        //StringBuilder stringBuilder = new StringBuilder();
        
        if (byteSrc == null || byteSrc.length <= 0)
        {
            return null;
        }
        
        String[] hexArray = new String[byteSrc.length];
        for (int i = 0; i < byteSrc.length; i++)
        {
            int iHex = byteSrc[i] & 0xFF;
            String sHex = Integer.toHexString(iHex);
            if (sHex.length() < 2)
            {
                hexArray[i] = "0" + sHex;
            }
            else
            {
                hexArray[i] = sHex;
            }
            
        }
        return hexArray;
    }


發佈了68 篇原創文章 · 獲贊 20 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章