Binary to Octal Convert Using JavaScript With HTML

Hello Friends Today, through this tutorial, I will tell you How to Binary to octal Convert Using Javascript with HTML? You can create a simple HTML page with JavaScript to convert a binary number to octal. Here’s an example:


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Binary to Octal Converter</title>
<h1>Binary to Octal Converter</h1>
<label for="binaryInput">Enter Binary Number:</label>
<input type="text" id="binaryInput" placeholder="Enter binary number">
<button onclick="convert()">Convert</button>
<p id="result"></p>
function convert() {
var binaryInput = document.getElementById("binaryInput").value;
var decimalNumber = parseInt(binaryInput, 2);
var octalNumber = decimalNumber.toString(8);
document.getElementById("result").innerText = "Octal Equivalent: " + octalNumber;

This simple HTML page includes an input field for entering a binary number, a button to trigger the conversion, and a paragraph to display the octal equivalent. The JavaScript function `convert()` takes the input, converts it to a decimal number using `parseInt()` with base 2, and then converts the decimal number to octal using `toString(8)`. The result is then displayed on the page.