package com.yutou.biliapi.utils;

import com.yutou.common.utils.Log;
import jakarta.xml.bind.DatatypeConverter;

public class BytesUtils {

    public static int bytesToInt2(byte[] src, int offset) {
        int value;
        value = (int) (((src[offset] & 0xFF) << 24)
                | ((src[offset + 1] & 0xFF) << 16)
                | ((src[offset + 2] & 0xFF) << 8)
                | (src[offset + 3] & 0xFF));
        return value;
    }

    public static void printHex(byte[] byteArray) {
        Log.i("\n\n\n");
        String str = DatatypeConverter.printHexBinary(byteArray);
        Log.i(str);
        for (int i = 0; i < str.length(); i = i + 4) {
            if (i % 32 == 0 && i != 0) {
                Log.i();
            }
            if (str.length() - i > 4) {
                System.out.print(str.substring(i, i + 4) + "  ");
            } else {
                Log.i(str.substring(i));
            }
        }
        Log.i("\n\n\n");
    }
    public static byte[] toLH(int n) {
        byte[] b = new byte[4];
        b[3] = (byte) (n & 0xff);
        b[2] = (byte) (n >> 8 & 0xff);
        b[1] = (byte) (n >> 16 & 0xff);
        b[0] = (byte) (n >> 24 & 0xff);
        return b;
    }
}
