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:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Binary to Octal Converter</title>
</head>
<body>
<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>
<script>
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;
}
</script>
</body>
</html>

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.