package com.hdl.sdk.link.core.utils; /** * Created by hxb on 2022/8/5. */ public class ByteUtils { public static String encodeHexString(byte[] data) { StringBuilder sb = new StringBuilder(); for (byte b : data) { String hex = Integer.toHexString(0xFF & b); if (hex.length() == 1) { sb.append('0'); } sb.append(hex).append(' '); } return sb.toString(); } public static String encodeHexString(byte b) { return String.format("%02x ", b); } /** * byte转int */ public static int ByteToInt(byte value) { return 0xFF & value; } public static int ByteToInt(byte []value) { return ByteToInt(value[0]) * 256 + ByteToInt(value[1]); } public static byte[] IntToByte(int value) { return new byte[]{(byte) (value / 256), (byte) (value % 256)}; } }