ASCII To Binary Converter Tool Code, Completely Tested and verified and written in Javascript, HTML and Css.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ASCII to Binary Converter</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(to right, #4facfe, #00f2fe);
color: #333;
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
max-width: 500px;
width: 100%;
}
h1 {
text-align: center;
color: #4facfe;
}
.form-group {
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
resize: vertical;
}
button {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
background-color: #4facfe;
color: white;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #00c6fb;
}
.result {
margin-top: 20px;
background: #f9f9f9;
padding: 15px;
border-radius: 5px;
border: 1px solid #ddd;
}
.result pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
@media (max-width: 768px) {
body {
padding: 10px;
}
.container {
padding: 15px;
}
button {
font-size: 14px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>ASCII to Binary Converter</h1>
<div class="form-group">
<label for="asciiInput">Enter ASCII Text:</label>
<textarea id="asciiInput" rows="5" placeholder="Type your ASCII text here..."></textarea>
</div>
<button onclick="convertToBinary()">Convert to Binary</button>
<div class="result" id="binaryOutput" style="display: none;">
<h3>Binary Output:</h3>
<pre id="binaryText"></pre>
</div>
</div>
<script>
function convertToBinary() {
const asciiInput = document.getElementById('asciiInput').value;
const binaryOutput = document.getElementById('binaryOutput');
const binaryText = document.getElementById('binaryText');
if (!asciiInput) {
alert('Please enter ASCII text to convert.');
return;
}
const binaryResult = asciiInput
.split('')
.map(char => char.charCodeAt(0).toString(2).padStart(8, '0'))
.join(' ');
binaryText.textContent = binaryResult;
binaryOutput.style.display = 'block';
}
</script>
</body>
</html>