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
 IS PUBG MOBILE INDIA COMING ? As lakhs of PUBG Mobile India fans in the country are waiting for the relaunch of the hugely popular mobile in India, several new reports have claimed that PUBG Mobile India would soon be launched in India as the government has recently given permission to relaunch PUBG Mobile India. It may be recalled that  PUBG Mobile India  was banned by the Indian government in September 2020 due to privacy concerns. Some reports claimed that PUBG Corp is gearing up to launch  PUBG Mobile India  in the next two months. The speculations grew stronger after PUBG Corporation also posted a new job listing on LinkedIn for the India subsidiary. The job opening is for n Investment and Strategy Analyst who will take care of mergers and acquisitions in the country. PUBG has now also posted another job posting on LinkedIn, a Product Manager in the country. Notably, PUBG now has six job listings listed under PUBG Corporation, sending a strong message that  PUBG Mobile India  wo

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