[removed] reading 3 bytes Buffer as an integer

前端 未结 3 1152
小蘑菇
小蘑菇 2021-02-07 02:04

Let\'s say I have a hex data stream, which I want to divide into 3-bytes blocks which I need to read as an integer.

For example: given a hex string 01be638119704d4

3条回答
  •  离开以前
    2021-02-07 02:28

    you should convert three byte to four byte.

    function three(var sample){
        var buffer = new Buffer(sample, 'hex');
    
        var buf = new Buffer(1);
        buf[0] = 0x0;
    
        return Buffer.concat([buf, buffer.slice(0, 3)]).readUInt32BE();
    }
    

    You can try this function.

提交回复
热议问题