title: Understanding converting big endian to/from string
body: <p>Looking at these implementations, I am wondering if one could explain the reason behind the specific operations. Not coming from computer science, I am not sure why these decisions were made.</p>
  
  <pre><code>function binb2rstr(input) {
    var str = []
    for (var i = 0, n = input.length * 32; i &lt; n; i += 8) {
      var code = (input[i &gt;&gt; 5] &gt;&gt;&gt; (24 - i % 32)) &amp; 0xFF
      var val = String.fromCharCode(code)
      str.push(val)
    }
    return str.join('')
  }
  
  function rstr2binb(input) {
    var output = Array(input.length &gt;&gt; 2)
  
    for (var i = 0, n = output.length; i &lt; n; i++) {
      output[i] = 0
    }
  
    for (var i = 0, n = input.length * 8; i &lt; n; i += 8) {
      output[i &gt;&gt; 5] |= (input.charCodeAt(i / 8) &amp; 0xFF) &lt;&lt; (24 - i % 32)
    }
  
    return output
  }
  </code></pre>
  
  <p>What I understand so far are:</p>
  
  <ol>
  <li><code>i += 8</code> is for iterating through bytes.</li>
  <li><code>0xFF</code> is 255, which is <code>2^8 - 1</code>, so 1 byte.</li>
  <li>32 which is the size of a <em>word</em>, or 4 bytes</li>
  <li><code>|</code> is bitwise OR, <code>&lt;&lt;</code>, <code>&gt;&gt;&gt;</code>, and <code>&amp;</code> are likewise bit operators.</li>
  <li>The <code>%</code> modulus keeps the value within that max value of <code>x = x % max</code>.</li>
  </ol>
  
  <p>What I don't understand is:</p>
  
  <ol>
  <li><code>i &gt;&gt; 5</code>, how that was picked.</li>
  <li><code>&amp; 0xFF</code>, how that was picked.</li>
  <li><code>24 - i % 32</code>, where the 24 came from.</li>
  <li><code>var code = (input[i &gt;&gt; 5] &gt;&gt;&gt; (24 - i % 32)) &amp; 0xFF</code>, how the character code is computed from that.</li>
  <li><code>input.length &gt;&gt; 2</code></li>
  </ol>
  
  <p>Wondering if this is just a standard computer science function because it's hard to tell where these variables come from and how this was learned. It seems like these values must be a standard algorithm based on byte length but I can't tell how to get there with these open questions. Thank you for your help.</p>