How to convert long data to ArrayBuffer 64-bit binary data?

the front and back end communicates with websocket. How does the front end convert long data into ArrayBuffer 64-bit binary data

Feb.27,2021

just started to use bit operation, all the way up to 64 bits, but found that js bit operation can only reach 31 bits. And then higher is another loop.
so I think of converting the decimal to hexadecimal, and then taking the high bit and doing it again

    function long2bin(p) {
        var r = new ArrayBuffer(8);
        r[7] = p & 0xff;
        r[6] = p >> 8 & 0xff;
        r[5] = p >> 16 & 0xff;
        r[4] = p >> 24 & 0xff;
        p = p.toString(16); //16,
        if (p.length <= 8) {
            return r;
        }
        p = parseInt(p.substr(0, p.length - 8),16);//,int
        r[3] = p & 0xff;
        r[2] = p >> 8 & 0xff;
        r[1] = p >> 16 & 0xff;
        r[0] = p >> 24 & 0xff;
        return r;
    }
    var l = 1234567891011;
    long2bin(l);

var num = 12
var ab = new ArrayBuffer(1)
ab[0] = num
Menu