Skip to main content

HTML code which convert sentence to binary or vice-versa

 INTRODUCTION

Binary is a number system that uses only two digits, typically represented by 0 and 1. This system is widely used in digital electronics and computer programming because it is easy to represent using electronic devices that can be either "on" or "off", which correspond to the binary digits of 1 and 0.

In binary, each digit (or bit) represents a power of 2, with the rightmost bit representing 2^0 (or 1), the next bit representing 2^1 (or 2), and so on. To represent a number in binary, you can add up the values of the bits that are set to 1. For example, the binary number 1011 represents the decimal number 11, because 1 x 2^3 + 0 x 2^2 + 1 x 2^1 + 1 x 2^0 = 8 + 0 + 2 + 1 = 11.

Binary is also used to represent data in computers, where each character is represented by a unique combination of 1s and 0s. For example, the letter "A" might be represented by the binary sequence 01000001. This allows computers to store, transmit, and process data using electronic circuits that can easily distinguish between on and off states.

MAIN CONTENT

<!DOCTYPE html>
<html>
  <head>
    <title>Binary Converter</title>
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
    <script src="https://kit.fontawesome.com/2b0d9a2ad2.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="style.css">
    <script>
      function binaryToSentence() {
        // Get the input value
        const input = document.getElementById("binary-input").value.trim();
        
        // Split the binary input into an array of bytes
        const bytes = input.match(/.{1,8}/g);
        
        // Convert each byte to a character and join the characters to form the sentence
        const sentence = bytes.map(byte => String.fromCharCode(parseInt(byte, 2))).join("");
        
        // Display the result
        const result = document.getElementById("result");
        result.innerText = sentence;
        result.style.color = "#fff";
        result.style.backgroundColor = "#29b6f6";
        result.style.animation = "fade-in 0.5s ease-out";
      }
      
      function sentenceToBinary() {
        // Get the input value
        const input = document.getElementById("sentence-input").value.trim();
        
        // Convert each character to a binary string and join the strings to form the binary
        const binary = input.split("").map(char => char.charCodeAt(0).toString(2).padStart(8, "0")).join("");
        
        // Display the result
        const result = document.getElementById("result");
        result.innerText = binary;
        result.style.color = "#fff";
        result.style.backgroundColor = "#f44336";
        result.style.animation = "fade-in 0.5s ease-out";
      }
    </script>
  </head>
  <body>
    <div class="container">
      <h1>Binary Converter</h1>
      <div class="converter">
        <div class="form">
          <label for="binary-input">Enter binary:</label>
          <input type="text" id="binary-input" placeholder="01000001 01100010 01100011" />
          <button onclick="binaryToSentence()">Convert to sentence</button>
          <label for="sentence-input">Enter sentence:</label>
          <input type="text" id="sentence-input" placeholder="Abc" />
          <button onclick="sentenceToBinary()">Convert to binary</button>
        </div>
        <div class="result">
          <div id="result"></div>
        </div>
      </div>
    </div>
  </body>
</html>





Comments

Popular posts from this blog

Father of Modern Genetic : Sir Gregor Johann Mendel

 Early Life and Education: Gregor Mendel was born into a German-speaking family in the village of Heinzendorf, in the Austrian Empire (now the Czech Republic), on July 20, 1822. He was the son of Anton Mendel and Rosine Schwirtlich, both of whom were farmers. At the age of 11, Mendel was sent to a nearby school in Troppau, where he received his elementary education. In 1840, at the age of 18, Mendel began his studies at the University of Olomouc, where he studied philosophy, mathematics, physics, and natural history. In 1843, he entered the Augustinian monastery of St. Thomas in Brno, where he took the name Gregor and began his training as a monk. It was during his time at the monastery that he became interested in botany and began conducting experiments on the inheritance of traits in plants. Experiments with Pea Plants: Between 1856 and 1863, Mendel conducted a series of experiments on pea plants in the monastery's garden. He chose pea plants because they were easy to grow, had a

how to study for long hours

HOW TO STUDY FOR LONG HOURS:-   1. Prioritize your schedule: take up difficult topics early in the day Take up the difficult material in the forenoon when you’re at your best, energy wise. (For most people this is the time when they’re most productive. If somehow you’re an exception to this, feel free to take up the difficult material at a time that works for you.) Such scheduling matches your energy with the difficulty of the task at hand. As a result, you face less challenging topics in the evening, by when you’ve dissipated loads of your physical and mental energy and when tendency to slack is highest. On the contrary, if you pick easy stuff early in the day to get a false sense of progress – which many procrastinators do – you’re more likely to succumb to procrastination and give up later in the day when your energy and resolve would hate being tested. For the same reason, to the extent possible, schedule your low-effort, non-academi

QUANTUM PHYSICS AND HISTORY

  Introduction to Quantum Physics Quantum physics is a branch of physics that deals with the study of the behavior of matter and energy at a very small scale. It is a fundamental theory that explains the behavior of subatomic particles such as electrons, protons, and neutrons, which make up the building blocks of matter. Unlike classical physics, which deals with the laws of motion and the behavior of macroscopic objects, quantum physics deals with the laws of probability and the behavior of particles at the quantum level. Historical Development of Quantum Physics The development of quantum physics can be traced back to the late 19th century when scientists such as Max Planck and Albert Einstein were studying the behavior of light and electromagnetic radiation. In 1900, Planck proposed that the energy of electromagnetic radiation is quantized, meaning that it can only exist in discrete packets of energy known as quanta. This idea was revolutionary at the time and formed the basis for t