Reading bytes from a JavaScript string

前端 未结 9 1319
悲哀的现实
悲哀的现实 2020-11-28 02:46

I have a string containing binary data in JavaScript. Now I want to read, for example, an integer from it. So I get the first 4 characters, use charCodeAt, do s

9条回答
  •  清酒与你
    2020-11-28 03:37

    borgars solution improvement:

    ...
    do {
          st.unshift( ch & 0xFF );  // push byte to stack
          ch = ch >> 8;          // shift value down by 1 byte
        }  
        while ( ch );
        // add stack contents to result
        // done because chars have "wrong" endianness
        re = re.concat( st );
    ...
    

提交回复
热议问题