Best way to get two nibbles out of a byte in javascript?

后端 未结 3 809
故里飘歌
故里飘歌 2021-02-04 05:57

I\'m parsing a binary file in javascript that is storing two pieces of information per byte, one per nibble. The values are, of course, 0-16 and 0-16.

In all other parts

3条回答
  •  故里飘歌
    2021-02-04 06:09

    var num = str.charCodeAt(0) & 0xFF;
    var nibble1 = num & 0xF;
    var nibble2 = num >> 4;
    

提交回复
热议问题