Here's a complete solution that includes both:
✅ 1. HTML Page (No Installation Required)
This is a standalone HTML file that runs entirely in the browser using JavaScript.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text to Binary Converter</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
textarea { width: 100%; height: 100px; margin-top: 10px; }
button { margin-top: 10px; padding: 10px 20px; }
.result { margin-top: 20px; white-space: pre-wrap; }
</style>
</head>
<body>
<h2>Text ↔ Binary Converter</h2>
<h3>Text to Binary</h3>
<textarea id="textInput" placeholder="Enter text here..."></textarea>
<button onclick="textToBinary()">Convert to Binary</button>
<div class="result" id="textResult"></div>
<h3>Binary to Text</h3>
<textarea id="binaryInput" placeholder="Enter binary (e.g., 0100100001100101)..."></textarea>
<button onclick="binaryToText()">Convert to Text</button>
<div class="result" id="binaryResult"></div>
<script>
function textToBinary() {
const text = document.getElementById('textInput').value;
let binary = '';
for (let i = 0; i < text.length; i++) {
const charCode = text.charCodeAt(i);
const bin = charCode.toString(2).padStart(8, '0');
binary += bin;
}
document.getElementById('textResult').textContent = binary;
}
function binaryToText() {
const binary = document.getElementById('binaryInput').value;
if (binary.length % 8 !== 0) {
document.getElementById('binaryResult').textContent = "Error: Binary must be a multiple of 8 bits.";
return;
}
let text = '';
for (let i = 0; i < binary.length; i += 8) {
const chunk = binary.substring(i, i + 8);
const charCode = parseInt(chunk, 2);
text += String.fromCharCode(charCode);
}
document.getElementById('binaryResult').textContent = text;
}
</script>
</body>
</html>
✅ 2. Batch File (Requires Python Installed)
This .bat file assumes you have Python installed and the script saved as bit_calculator.py.
📁 Step 1: Save the following Python script as bit_calculator.py:
def text_to_binary(text):
return ''.join(format(ord(char), '08b') for char in text)
def binary_to_text(binary):
chunks = [binary[i:i+8] for i in range(0, len(binary), 8)]
return ''.join(chr(int(chunk, 2)) for chunk in chunks)
def main():
print("=== Bit Calculator ===")
print("1. Text to Binary")
print("2. Binary to Text")
choice = input("Choose an option (1 or 2): ")
if choice == '1':
text = input("Enter text: ")
print("Binary:", text_to_binary(text))
elif choice == '2':
binary = input("Enter binary (e.g., 0100100001100101): ")
try:
print("Text:", binary_to_text(binary))
except ValueError:
print("Error: Invalid binary input. Make sure it's a valid 8-bit string.")
else:
print("Invalid choice. Please select 1 or 2.")
if __name__ == "__main__":
main()