Home  >  Q&A  >  body text

javascript - An English string has a length of 1, occupies one byte, and each byte occupies 8 bits. How does js get the number of each bit in the memory?

As the title states, this problem comes from the interaction with hardware

The hardware passes a character to the front end. The front end needs to obtain the 8 bits this character occupies in the memory, how many each bit is, and then make some specific responses,

Please give me full stack advice~~

大家讲道理大家讲道理2736 days ago667

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 13:30:32

    var n = 100; // 4 + 32 + 64, 0110 0100
    for (var i = 0; n != 0; n >>= 1)
    {
        console.log(n & 1);
    }

    The result output from low to high is: 0 0 1 0 0 1 1

    reply
    0
  • Cancelreply