Please enter valid binary numbers (0s and 1s only).
Quick Binary/Decimal Converter
Binary Result:–
Decimal Result:–
Understanding Binary Numbers
Binary numbers form the fundamental language of modern computing. Unlike the decimal system (Base-10) we use in daily life, which relies on ten digits (0-9), the binary system (Base-2) uses only two digits: 0 and 1. Every piece of data, from this text to the highest-resolution video, is processed by computers as a sequence of these two bits.
How Binary Calculation Works
Calculating with binary involves the same principles as decimal math, but with much simpler rules because there are fewer digits to manage. When you add binary numbers, for example, the core rules are:
0 + 0 = 0
0 + 1 = 1
1 + 1 = 10 (which is 0, carry over 1)
1 + 1 + 1 = 11 (which is 1, carry over 1)
Binary to Decimal Conversion Chart
Decimal
Binary
Power of 2 Calculation
1
0001
2^0
2
0010
2^1
4
0100
2^2
8
1000
2^3
16
10000
2^4
Real-World Applications
Binary calculation is used in virtually every aspect of technology:
CPU Processing: Transistors inside processors act as switches that are either ON (1) or OFF (0).
IP Addressing: IPv4 addresses are 32-bit binary numbers, though we usually write them in dotted-decimal format for humans.
Data Storage: Hard drives and SSDs store data by changing magnetic polarity or electrical charge, representing 0s and 1s.
Cryptography: Encryption algorithms use complex binary arithmetic (like XOR gates) to secure sensitive information.
Example Calculation
If you want to add binary 1010 (Decimal 10) and 0101 (Decimal 5):
1010
+ 0101
——-
1111 (Decimal 15)
function calculateBinary() {
var b1 = document.getElementById("binary1").value;
var b2 = document.getElementById("binary2").value;
var op = document.getElementById("operation").value;
var error = document.getElementById("errorMsg");
var resultBox = document.getElementById("arithmeticResultBox");
if (b1 === "" || b2 === "") {
error.style.display = "block";
error.innerText = "Please enter both binary numbers.";
resultBox.style.display = "none";
return;
}
// Convert binary strings to decimal integers
var d1 = parseInt(b1, 2);
var d2 = parseInt(b2, 2);
var resDecimal;
if (isNaN(d1) || isNaN(d2)) {
error.style.display = "block";
error.innerText = "Invalid binary input.";
resultBox.style.display = "none";
return;
}
error.style.display = "none";
switch(op) {
case "add":
resDecimal = d1 + d2;
break;
case "subtract":
resDecimal = d1 – d2;
break;
case "multiply":
resDecimal = d1 * d2;
break;
case "divide":
if (d2 === 0) {
error.style.display = "block";
error.innerText = "Division by zero is not allowed.";
resultBox.style.display = "none";
return;
}
resDecimal = Math.floor(d1 / d2);
break;
default:
resDecimal = 0;
}
// Convert back
var finalBin = (resDecimal >>> 0).toString(2); // Handle negative numbers with unsigned right shift for simple display
if (resDecimal < 0) {
finalBin = "-" + Math.abs(resDecimal).toString(2);
}
document.getElementById("resBin").innerText = finalBin;
document.getElementById("resDec").innerText = resDecimal;
document.getElementById("resHex").innerText = resDecimal.toString(16).toUpperCase();
resultBox.style.display = "block";
}
function convertDecToBin() {
var dec = document.getElementById("decInput").value;
var out = document.getElementById("convBin");
if (dec === "") {
out.innerText = "-";
return;
}
var num = parseInt(dec);
out.innerText = num.toString(2);
}
function convertBinToDec() {
var bin = document.getElementById("binInput").value;
var out = document.getElementById("convDec");
if (bin === "") {
out.innerText = "-";
return;
}
var num = parseInt(bin, 2);
if (isNaN(num)) {
out.innerText = "Invalid";
} else {
out.innerText = num;
}
}