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

ALL ABOUT ELON MUSK

 Elon Musk is a billionaire entrepreneur, inventor, and engineer who has gained widespread recognition for his contributions to the fields of space exploration, electric vehicles, and sustainable energy. He is known for his ambitious and visionary ideas, as well as his relentless work ethic and ability to execute on his plans. In this essay, we will explore his life, career, and impact in detail. Early Life and Education Elon Musk was born on June 28, 1971, in Pretoria, South Africa, to a Canadian mother and a South African father. He grew up in a family of entrepreneurs, as his mother owned a successful nutrition company, and his father owned a mine consulting business. From a young age, Musk showed a strong interest in technology and innovation, and he taught himself how to code at the age of 12. After finishing high school, Musk attended the University of Pretoria for a brief period before moving to the United States to study at the University of Pennsylvania. He earned a bachel...

ALL ABOUT BILL GATES

  Bill Gates is a household name that is synonymous with technology and innovation. Born on October 28th, 1955, in Seattle, Washington, William Henry Gates III, popularly known as Bill Gates, is an American business magnate, software developer, and philanthropist. He is the co-founder of Microsoft Corporation, the world's largest personal-computer software company. Bill Gates is one of the wealthiest people in the world and has become an inspiration to many aspiring entrepreneurs. Early Life and Education Bill Gates was born to Mary Maxwell Gates and William Henry Gates Jr. He has two sisters, Kristi and Libby. His father was an attorney, and his mother served on several corporate boards. As a child, Gates was an avid reader, and his parents encouraged him to pursue his interests. In 1967, at the age of 12, he enrolled in Lakeside School, a private preparatory school in Seattle. It was at Lakeside School that Gates first became interested in computers. In 1973, Gates enrolled at Ha...