Easily convert numbers between binary and decimal systems with this free online tool. Instant conversion with educational visualization.
Convert between binary and decimal number systems instantly.
Binary numbers use only 0s and 1s
Decimal numbers use digits 0-9
Enter a value in either field to see the conversion in the other field.
The Binary-Decimal Converter is an essential tool for anyone working with different number systems. Binary (base-2) and decimal (base-10) are two fundamental numerical systems used in computing and mathematics. Our binary to decimal converter allows you to instantly translate numbers between these systems with perfect accuracy. Whether you're a computer science student learning about binary representation, a programmer debugging code, or an electronics enthusiast working with digital circuits, this converter simplifies the process of converting between binary and decimal number formats without requiring complex manual calculations.
Binary numbers, consisting only of 0s and 1s, form the foundation of all digital computing systems, while the decimal system with digits 0-9 is what we use in everyday life. Understanding the relationship between these systems is crucial for anyone involved in computer science, programming, or digital electronics. This tool bridges the gap between these number systems, making conversions effortless and error-free.
The decimal system is our standard number system, using 10 digits (0-9). In this positional number system, each digit's position represents a power of 10:
For example, the decimal number 427 represents:
Adding these values: 400 + 20 + 7 = 427
The binary system uses only two digits (0 and 1). Each position in a binary number represents a power of 2:
For example, the binary number 1010 represents:
Adding these values: 8 + 0 + 2 + 0 = 10 in decimal
To convert a binary number to decimal, multiply each digit by its corresponding power of 2 and sum the results:
Where:
Example: Converting binary 1101 to decimal
To convert a decimal number to binary, repeatedly divide the number by 2 and record the remainders in reverse order:
Example: Converting decimal 25 to binary
Our binary-decimal converter is designed to be intuitive and user-friendly. Follow these simple steps to convert between binary and decimal numbers:
The converter also provides a visual explanation of the conversion process, showing you exactly how each conversion is performed mathematically. This educational feature helps you understand the underlying principles of number system conversions.
Binary-decimal conversion is fundamental in numerous fields and applications:
An IPv4 address like 192.168.1.1 can be represented in binary as:
Combined: 11000000.10101000.00000001.00000001
While binary and decimal are the most commonly used number systems, other systems have important applications:
Hexadecimal uses 16 digits (0-9 and A-F) and is often used as a more compact way to represent binary data. Each hexadecimal digit represents exactly 4 binary digits.
Example: Binary 1010 1101 = Hexadecimal AD
Octal uses 8 digits (0-7) and was historically important in computing. Each octal digit represents exactly 3 binary digits.
Example: Binary 101 011 = Octal 53
BCD represents each decimal digit using a fixed number of binary digits (typically 4). It's used in applications where decimal representation is required, such as digital clocks.
Example: Decimal 42 in BCD = 0100 0010
The decimal system has been the predominant number system in human history, likely because humans have ten fingers. Evidence of decimal counting systems dates back to ancient civilizations:
The binary system has a more recent but equally fascinating history:
Here are implementations of binary-decimal conversion in various programming languages:
1// Binary to Decimal conversion
2function binaryToDecimal(binary) {
3 if (!/^[01]+$/.test(binary)) {
4 return "Invalid binary number";
5 }
6 return parseInt(binary, 2);
7}
8
9// Decimal to Binary conversion
10function decimalToBinary(decimal) {
11 if (!/^\d+$/.test(decimal) || decimal < 0) {
12 return "Invalid decimal number";
13 }
14 return Number(decimal).toString(2);
15}
16
17// Example usage
18console.log(binaryToDecimal("1010")); // Outputs: 10
19console.log(decimalToBinary("42")); // Outputs: 101010
20
1# Binary to Decimal conversion
2def binary_to_decimal(binary):
3 try:
4 # Check if the input contains only 0s and 1s
5 if not all(bit in '01' for bit in binary):
6 return "Invalid binary number"
7 return int(binary, 2)
8 except ValueError:
9 return "Invalid binary number"
10
11# Decimal to Binary conversion
12def decimal_to_binary(decimal):
13 try:
14 # Check if the input is a non-negative integer
15 decimal = int(decimal)
16 if decimal < 0:
17 return "Invalid decimal number"
18 return bin(decimal)[2:] # Remove '0b' prefix
19 except ValueError:
20 return "Invalid decimal number"
21
22# Example usage
23print(binary_to_decimal("1010")) # Outputs: 10
24print(decimal_to_binary("42")) # Outputs: 101010
25
1public class BinaryDecimalConverter {
2 // Binary to Decimal conversion
3 public static int binaryToDecimal(String binary) {
4 if (!binary.matches("[01]+")) {
5 throw new IllegalArgumentException("Invalid binary number");
6 }
7 return Integer.parseInt(binary, 2);
8 }
9
10 // Decimal to Binary conversion
11 public static String decimalToBinary(int decimal) {
12 if (decimal < 0) {
13 throw new IllegalArgumentException("Negative numbers not supported");
14 }
15 return Integer.toBinaryString(decimal);
16 }
17
18 public static void main(String[] args) {
19 System.out.println(binaryToDecimal("1010")); // Outputs: 10
20 System.out.println(decimalToBinary(42)); // Outputs: 101010
21 }
22}
23
1#include <iostream>
2#include <string>
3#include <cmath>
4#include <regex>
5
6// Binary to Decimal conversion
7int binaryToDecimal(const std::string& binary) {
8 // Check if the input contains only 0s and 1s
9 if (!std::regex_match(binary, std::regex("[01]+"))) {
10 throw std::invalid_argument("Invalid binary number");
11 }
12
13 int decimal = 0;
14 for (int i = 0; i < binary.length(); i++) {
15 if (binary[binary.length() - 1 - i] == '1') {
16 decimal += std::pow(2, i);
17 }
18 }
19 return decimal;
20}
21
22// Decimal to Binary conversion
23std::string decimalToBinary(int decimal) {
24 if (decimal < 0) {
25 throw std::invalid_argument("Negative numbers not supported");
26 }
27
28 if (decimal == 0) {
29 return "0";
30 }
31
32 std::string binary = "";
33 while (decimal > 0) {
34 binary = (decimal % 2 == 0 ? "0" : "1") + binary;
35 decimal /= 2;
36 }
37 return binary;
38}
39
40int main() {
41 std::cout << binaryToDecimal("1010") << std::endl; // Outputs: 10
42 std::cout << decimalToBinary(42) << std::endl; // Outputs: 101010
43 return 0;
44}
45
1' Binary to Decimal conversion
2Function BinaryToDecimal(binary As String) As Variant
3 ' Check if the input contains only 0s and 1s
4 Dim i As Integer
5 For i = 1 To Len(binary)
6 If Mid(binary, i, 1) <> "0" And Mid(binary, i, 1) <> "1" Then
7 BinaryToDecimal = CVErr(xlErrValue)
8 Exit Function
9 End If
10 Next i
11
12 BinaryToDecimal = Application.WorksheetFunction.Bin2Dec(binary)
13End Function
14
15' Decimal to Binary conversion
16Function DecimalToBinary(decimal As Long) As String
17 If decimal < 0 Then
18 DecimalToBinary = CVErr(xlErrValue)
19 Exit Function
20 End If
21
22 DecimalToBinary = Application.WorksheetFunction.Dec2Bin(decimal)
23End Function
24
25' Example usage in a cell:
26' =BinaryToDecimal("1010") ' Returns: 10
27' =DecimalToBinary(42) ' Returns: 101010
28
A binary number is a number expressed in the base-2 numeral system, which uses only two symbols: typically "0" and "1". Each digit is referred to as a bit (binary digit). Binary numbers are fundamental to digital computing since all data in computers is ultimately represented in binary form.
Computers use binary because electronic components can easily represent two states: on/off, high/low voltage, or magnetic polarities. Binary is also mathematically simpler to implement in hardware, making computers more reliable and efficient. Additionally, Boolean logic (AND, OR, NOT) maps perfectly to binary operations.
To convert a binary number to decimal manually:
For example, binary 1101: 1×8 + 1×4 + 0×2 + 1×1 = 8 + 4 + 0 + 1 = 13
To convert a decimal number to binary manually:
For example, decimal 13: 13 ÷ 2 = 6 remainder 1 6 ÷ 2 = 3 remainder 0 3 ÷ 2 = 1 remainder 1 1 ÷ 2 = 0 remainder 1 Reading from bottom to top: 1101
Our current implementation focuses on non-negative integers for simplicity and educational purposes. Negative numbers in binary typically use techniques like signed magnitude, one's complement, or two's complement representation, which are more advanced concepts.
The converter can handle integers up to JavaScript's safe integer limit (2^53 - 1), which is 9,007,199,254,740,991. For binary inputs, this means up to 53 bits. For extremely large numbers, specialized libraries would be required.
Decimal fractions are represented in binary using binary fractions. For example, 0.5 decimal is 0.1 binary (1×2^-1). The process involves multiplying the fractional part by 2 and recording the integer part until you reach 0 or start repeating. Our current converter focuses on integers only.
Common errors include:
Computer memory is organized as a sequence of addressable locations. Each location has a unique address, which is essentially a number. These addresses are represented in binary within the computer's circuitry. When a program needs to access memory, it specifies the binary address of the desired location.
All three are positional number systems but with different bases. Hexadecimal and octal are often used as more compact ways to represent binary data, with each hexadecimal digit representing 4 binary digits and each octal digit representing 3 binary digits.
Knuth, Donald E. "The Art of Computer Programming, Volume 2: Seminumerical Algorithms." Addison-Wesley, 1997.
Leibniz, Gottfried Wilhelm. "Explication de l'Arithmétique Binaire" (Explanation of Binary Arithmetic). Mémoires de l'Académie Royale des Sciences, 1703.
Boole, George. "An Investigation of the Laws of Thought." Dover Publications, 1854 (republished 1958).
Shannon, Claude E. "A Symbolic Analysis of Relay and Switching Circuits." Transactions of the American Institute of Electrical Engineers, vol. 57, no. 12, 1938, pp. 713-723.
Ifrah, Georges. "The Universal History of Numbers: From Prehistory to the Invention of the Computer." Wiley, 2000.
"Binary Number." Wikipedia, Wikimedia Foundation, https://en.wikipedia.org/wiki/Binary_number. Accessed 15 Aug. 2023.
"Decimal." Wikipedia, Wikimedia Foundation, https://en.wikipedia.org/wiki/Decimal. Accessed 15 Aug. 2023.
"Number System Conversion." National Institute of Standards and Technology, https://www.nist.gov/dads/HTML/numbersysconv.html. Accessed 15 Aug. 2023.
Try our Binary-Decimal Converter now to quickly and accurately convert between binary and decimal number systems. Whether you're studying computer science, working on digital electronics projects, or just curious about how computers represent numbers, our tool makes the conversion process simple and educational.
Discover more tools that might be useful for your workflow