Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
var demoMemory = [];
function stringToArray(str) {
  var i,
      length = str.length,
      arr = [];
  
  for(i=0; i<length; i+=4) {
    arr.push(
      (((str.charCodeAt(i)   || 0) << 24)
      |((str.charCodeAt(i+1) || 0) << 16)
      |((str.charCodeAt(i+2) || 0) << 8)
      |((str.charCodeAt(i+3) || 0)))
    );
  }
  
  if(length % 4 === 0) {
    arr.push(0);
  }
  
  return arr;
}
function arrayToString(arr) {
  var i, j, chrCode,
      length = arr.length,
      str = [];
  
  label:
  for(i=0; i<length; i++) {
    for(j=24; j>=0; j-=8) {
      chrCode = (arr[i] >> j) & 0xFF;
      if(chrCode) {
        str.push(String.fromCharCode(chrCode));
      } else {
        break label;
      }
    }
  }
  
  return str.join('');
}
console.log(demoMemory = stringToArray('Hello, World!')); // => [1214606444, 1865162839, 1869769828, 553648128]
console.log(arrayToString(demoMemory)); // "Hello, World!"
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers