-2
如何反轉這個函數?它從文本中創建一個80位的二進制代碼,我在互聯網上發現它,但不知道如何反轉操作並使得到的二進制代碼恢復文本。ASCII轉二進制函數
var ascii2bin = function(ascii)
{
var bin = "00000000000000000000000000000000000000000000000000000000000000000000000000000000";
for (var i = 0; i < ascii.length; i++)
{
var code = ascii.charCodeAt(i);
bin += ('00000000' + code.toString(2)).slice(-8);
}
return bin.slice(-10 * 8).split('').reverse();
}
您可能正在尋找['parseInt(...,2)'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)讀取二進制字節作爲char代碼值es,然後['String.fromCharCode'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)將char代碼值轉換爲字符。 – apsillers