二进制和16进制互相转换

  private static String byteToHex(byte[] bytes) {
        StringBuilder hex = new StringBuilder();
        for (byte b : bytes) {
            hex.append(HEXES[(b >> 4) & 0x0f]);
            hex.append(HEXES[b & 0x0f]);
        }
        return hex.toString();
    }

    public static byte[] hexStringToBytes(String str) {
        byte[] bs = new byte[str.length() / 2];
        for (int i = 0; i < bs.length; i++) {
            bs[i] = (byte) Integer.parseInt(str.substring(i * 2, i * 2 + 2), 16);
        }
        return bs;
    }
// f09f9191e88c 👑 
// f09d9c83 𝜃
// f4808284 􀂄
// f09d90bf 𝐿
// f09d9198 𝑘
 

 

posted @ 2022-10-02 21:22  zincredible  阅读(42)  评论(0编辑  收藏  举报