Home javascript Translation HTML HEX Tables in ASCII file

Translation HTML HEX Tables in ASCII file

Author

Date

Category


I need to write a code on JS, which would take a hex number from cells, then translated them into a binary and recorded a file in the ASCII encoding.

function download ()
{
  var str = "";
  Var Str1 = ""; //
  var arr = []; //
  VAR VROWS = Document.getelementsByname ("Data"); // Get an array of cells
  for (var c = 0; c & lt; vrows.length; C++) // go in the cycle
  {
    STR1 = "0X" + VROWS [C] .innerhtml; // We enter the array of the cells and add 0x
    arr.push (Parseint (STR1,16)); // Parsim in Int
    STR + = String.Fromcharcode (Parseint (STR1,16)); // Correm the string from characters
  }
  Alert (STR); // Display (for yourself)
  var blob = new blob ([STR], {// Create a file and save
    Type: "Application / OCTET-STREAM"}); //
  Saveas (Blob, "Core.bin"); //
}

I already tried to translate into a binary of 16 and save, and what just did not try. Does not exceed. Saves in UTF8 and hover the text …


Answer 1, Authority 100%

First,
You want a strange.
ASCII This is a seven-bit encoding. In ASCII 128 characters. That is, 00-7F is the standard ASCII . And ascii -text is a valid UTF-8 , the same characters codes. ASCII Everywhere the same.

But you want 7F-FF characters, and this is already an eight-bit encoding, the so-called Extended Ascii . Not a specific encoding, and their family. And UTF-8 applies to this family. As belongs most encodings in which the first 128 characters are the same as in ASCII . And it would be nice to decide which you need if it is not UTF-8 . string.fromcharcode Returns a symbol from UTF-8 Tables.

second,
I do not know how to specify the browser in which encoding it is downloaded to save the file. It is likely that it is not yet. But the encoding is just a hint for a program that works with the data as this data is understood.

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

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions