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 tha...

Basics of logic gates

 Introduction: Logic gates are basic building blocks of digital electronics. They are electronic circuits that perform a logical operation on one or more inputs to produce a single output. Logic gates are used to design digital circuits for different applications such as computers, calculators, and digital watches. There are several types of logic gates, each with its own unique function and characteristics. In this article, we will discuss the different types of logic gates and their applications. Types of Logic Gates: There are seven types of logic gates: NOT, AND, OR, NAND, NOR, XOR, and XNOR gates. Each of these gates has a specific function and logic. NOT Gate: The NOT gate, also known as an inverter, is a simple logic gate with one input and one output. The output of the NOT gate is the opposite of the input. If the input is a 0, the output is a 1, and if the input is a 1, the output is a 0. The symbol for the NOT gate is a triangle with a small circle at the input. AND Gate:...