Here is the table I need to write a code on js that would take hex numbers from cells, then translate them into a binary and write it to a file in ASCII.

function download() { var str=""; var str1="";// var arr = [];// var vrows = document.getElementsByName("data");//ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ массив ячССк for(var c=0;c<vrows.length;c++)//ΠΈΠ΄Π΅ΠΌ Π² Ρ†ΠΈΠΊΠ»Π΅ { str1="0x"+vrows[c].innerHTML;//заносим Π² массив значСния ячССк ΠΈ добавляСм 0x arr.push(parseInt(str1,16));//парсим Π² ΠΈΠ½Ρ‚ str+=String.fromCharCode(parseInt(str1,16));//соибраСм строку ΠΈΠ· символов } alert (str);//Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ (для сСбя) var blob = new Blob([str], {//создаСм Ρ„Π°ΠΉΠ» ΠΈ сохраняСм type: "application/octet-stream"});// saveAs(blob, "core.bin");// } 

I have already tried to translate into a binary of 16 and save, and that just did not try. Does not exceed. Saves to UTF8 and distorts text ...

    1 answer 1

    First of all,
    You want strange.
    ASCII is a seven-bit encoding. The ASCII 128 characters. That is, 00-7F is standard ASCII . And ASCII text is valid UTF-8 , the same character codes. ASCII is the same everywhere.

    But you want 7F-FF characters, and this is already an eight-bit encoding, the so-called Extended ASCII . Not a specific encoding, but their family. And UTF-8 belongs to this family. Like most encodings, in which the first 128 characters are the same as in ASCII . And it would be nice to decide which one you need if it is not UTF-8 . String.fromCharCode returns a character from a UTF-8 table.

    Secondly,
    I don’t know how to tell the browser in what encoding to save the downloaded file. It is likely that it is not. But the encoding is just a hint for a program that works with data, how to understand this data.

    Thirdly,
    In this case, you can simply open the saved file in any text editor that can work with encodings and tell the editor in which encoding to understand this file. Because there were no irreversible changes in the data itself along the way.