How to efficiently read bits out of bytes?

前端 未结 4 1938
野的像风
野的像风 2021-01-02 02:24

I\'m working on a project that includes WebSockets, and data between the server (Node.js) and the client (Chrome) is sent using a custom (very simple) format for data exchan

4条回答
  •  情歌与酒
    2021-01-02 03:03

    The binary AND and bit shifting operations are the fastest way of doing this. They translate well into machine code instructions. The only way to further speed this up is by sacrificing bandwidth for speed by for example simply not using more than 3 bits per byte, but judging from your question you've probably already considered and rejected that tradeoff.

提交回复
热议问题