Binary
Calculator
Perform binary arithmetic (add, subtract, multiply, divide) and convert between binary, decimal, hexadecimal, and octal, with bit-level visualization, step-by-step breakdowns, and multi-base output.
—
Binary Calculator: Perform Binary Arithmetic and Conversions
Binary, the language of every computer, processor, and digital system, uses just two digits (0 and 1) to represent all data, instructions, and calculations. Whether you’re debugging bitwise operations, studying for a computer science exam, verifying network subnet masks, or exploring how processors perform arithmetic, working with binary directly builds the foundational understanding that separates proficient programmers from beginners. This free binary calculator performs all four arithmetic operations on binary numbers (addition, subtraction, multiplication, division), converts between binary, decimal, hexadecimal, and octal, displays results in all four bases simultaneously, shows a bit-level visualization table, and provides step-by-step calculation breakdowns.
🔢 Core concepts:
Binary (base-2): uses digits 0, 1, each position is a power of 2
Decimal (base-10): uses digits 0–9, the everyday number system
Hexadecimal (base-16): uses 0–9, A–F, compact binary representation
Octal (base-8): uses 0–7, legacy Unix permissions system
Example: binary 1010 = decimal 10 = hex A = octal 12
How the Binary Calculator Formula Works
This calculator measures the result of an arithmetic operation or base conversion by using decimal as an intermediate step. Rather than implementing separate binary-native, hex-native, and octal-native arithmetic engines, it converts your input to decimal, performs the operation using standard arithmetic, then converts the result back into binary and every other base for display. This is exactly how the calculator’s own parseBase() and toBase() functions work under the hood.
Arithmetic mode: Result = toBase( parseBase(A, 2) [operation] parseBase(B, 2), 2 )
Conversion mode: Result = toBase( parseBase(Value, FromBase), ToBase )
parseBase(str, base) reads a number written in a given base and returns its decimal value. toBase(num, base) takes a decimal value and returns its representation in the target base. Every operation the calculator performs, whether arithmetic or conversion, is built from these same two functions, which is why the result in every base stays perfectly consistent no matter which mode or operation you use.
Step-by-step calculation walkthrough
Step 1: Identify the inputs. Binary subtraction: 1100 minus 0101.
Step 2: Apply the formula. Convert both binary values to decimal: parseBase(“1100”, 2) and parseBase(“0101”, 2). Subtract the decimal values. Convert the decimal result back to binary with toBase().
Step 3: Perform the calculation. 1100₂ = 12 in decimal. 0101₂ = 5 in decimal. 12 − 5 = 7. Converting 7 back to binary: 111.
Step 4: Interpret the result. 1100 − 0101 = 111 in binary, matching 12 − 5 = 7 in decimal. The result also converts to 0x7 in hexadecimal and 7 in octal, all four bases shown simultaneously in the calculator’s results, since they all represent the exact same underlying decimal value of 7.
🔢 The bit table, step-by-step breakdown, and multi-base KPI row shown in your results all read from this same decimal-intermediate calculation. Switching between add, subtract, multiply, and divide in Arithmetic mode doesn’t change this underlying process, it only changes which arithmetic operator is applied to the two decimal values before converting back to binary.
Assumptions and limitations: the calculator handles unsigned integers using JavaScript’s native number arithmetic, which is exact for integers up to 2⁵³−1 (9,007,199,254,740,991). Negative results (from subtraction, for example) are displayed using 32-bit two’s complement representation rather than a minus sign in the binary output. Division always truncates toward zero (integer division), it doesn’t produce a binary fractional remainder or decimal point.
What Is a Binary Calculator? The Core Concept Explained
A binary calculator is a computational tool that performs arithmetic operations directly on binary numbers and converts between number bases. While any calculator can work with decimal numbers, a binary calculator displays inputs and outputs in base-2 format, shows the binary arithmetic process step by step, and presents results in multiple number systems simultaneously: essential for programming, networking, digital electronics, and computer science education.
The calculator above operates in two modes. In Arithmetic mode, you enter two binary numbers and select an operation (add, subtract, multiply, or divide): the calculator performs the operation and shows the binary result alongside its decimal, hexadecimal, and octal equivalents. In Conversion mode, you enter a number in any base (2, 8, 10, or 16) and convert it to any other base instantly. Both modes include a bit-level visualization showing each binary digit’s position and place value.
Understanding Binary Numbers
Binary is a positional number system with base 2, meaning each digit position represents a power of 2 (just as each decimal digit position represents a power of 10). Reading right to left, the positions represent 2⁰=1, 2¹=2, 2²=4, 2³=8, 2⁴=16, and so on. A binary digit (or “bit”) can only be 0 or 1, representing “off” or “on” in the physical circuits that make up computer hardware.
To find the decimal value of a binary number, sum the powers of 2 where the bit is 1. For example: 1010₂ = 1×8 + 0×4 + 1×2 + 0×1 = 8+2 = 10₁₀. The bit visualization in the calculator above shows this breakdown graphically, highlighting which bits are “on” and their corresponding place values.
Why Computers Use Binary
Computers use binary because digital electronic circuits have two stable states: high voltage (1) and low voltage (0). This maps perfectly to binary digits. Transistors (the fundamental building blocks of all processors) act as tiny switches that are either on or off. By combining billions of these binary switches, modern processors perform complex calculations, store data, render graphics, and run software, all using nothing but 0s and 1s.
Every piece of data you interact with (text, images, video, music, software) is ultimately stored and processed as binary. The letter “A” is 01000001 in ASCII binary. The colour white in RGB is 11111111 11111111 11111111. A 1080p video frame is approximately 50 million binary digits. Understanding binary is understanding the fundamental language of all digital technology.
Binary to Decimal Conversion
| Binary | Calculation | Decimal | Hex |
|---|---|---|---|
| 0001 | 1 | 1 | 1 |
| 0010 | 2 | 2 | 2 |
| 0100 | 4 | 4 | 4 |
| 1000 | 8 | 8 | 8 |
| 1010 | 8+2 | 10 | A |
| 1111 | 8+4+2+1 | 15 | F |
| 1111 1111 | 128+64+32+16+8+4+2+1 | 255 | FF |
| 1 0000 0000 | 256 | 256 | 100 |
Binary Arithmetic Explained
Binary addition follows the same column-by-column process as decimal addition, but with only two digits. The rules are: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (0 with carry 1), and 1+1+1=11 (1 with carry 1). Carries propagate left exactly as in decimal. Example: 1011 + 1101 → align and add each column right to left: 1+1=10 (write 0, carry 1), 1+0+1=10 (write 0, carry 1), 0+1+1=10 (write 0, carry 1), 1+1+1=11 (write 1, carry 1) → result: 11000 (decimal 24 = 11+13).
Binary subtraction uses borrowing, analogous to decimal subtraction. When subtracting a 1 from a 0, borrow from the next higher bit (a borrow in binary converts one higher-position bit into two lower-position bits). Binary subtraction is fundamental to how processors implement comparison operations and conditional logic.
Binary multiplication is simpler than decimal multiplication because each multiplier bit is either 0 (no contribution) or 1 (copy the multiplicand). The partial products are shifted left and added together. Binary multiplication is implemented in hardware as combinations of shift and add operations, the same principle the calculator uses.
Binary division follows long division logic but with binary. At each step, determine whether the divisor fits (1) or doesn’t fit (0) into the current portion of the dividend. The quotient bits are built left to right. Binary division is the most complex of the four operations in hardware implementation and is why division instructions are typically slower than multiplication on processors.
Binary vs Hexadecimal: The Programmer’s Shorthand
Hexadecimal (base-16) is the preferred compact representation of binary data because each hex digit maps to exactly 4 binary digits (bits). This makes conversion trivial: group binary digits in fours from the right, and convert each group to its hex equivalent (0000=0, 0001=1, …, 1001=9, 1010=A, 1011=B, 1100=C, 1101=D, 1110=E, 1111=F). For example, 1111 0000 1010 1100₂ = F0AC₁₆.
Programmers use hex constantly: memory addresses (0x7FFF0000), colour codes (#FF5733), MAC addresses (AA:BB:CC:DD:EE:FF), and binary file contents are all expressed in hexadecimal because it’s compact yet maintains a direct, lossless relationship with the underlying binary. The calculator’s simultaneous display of all four bases makes these relationships immediately visible.
Binary in Networking and IP Addressing
IP addresses
IPv4 addresses are 32-bit binary numbers displayed as four decimal octets. 192.168.1.1 = 11000000.10101000.00000001.00000001 in binary. Subnet calculations require binary AND operations.
Subnet masks
Subnet masks are binary patterns of consecutive 1s followed by 0s. /24 = 11111111.11111111.11111111.00000000 = 255.255.255.0. Binary AND between IP and mask gives the network address.
Cryptography
Encryption algorithms operate on binary data using XOR, shifts, and substitutions. AES, RSA, and SHA all manipulate data at the bit level. Understanding binary is prerequisite to understanding cryptography.
File formats
File headers, binary protocols, and data structures are defined in binary/hex. Reading a file’s hex dump requires fluent binary-hex conversion: the skill this calculator builds.
Bits and Bytes: The Units of Digital Storage
A bit is a single binary digit (0 or 1): the smallest unit of digital information. A byte is 8 bits, capable of representing 2⁸ = 256 different values (0–255 unsigned, or -128 to 127 signed). A nibble is 4 bits (one hexadecimal digit), representing 0–15. Common data sizes include 16-bit (short/word: 0 to 65,535), 32-bit (int: 0 to ~4.3 billion), and 64-bit (long: 0 to ~18.4 quintillion).
Storage units scale in powers of 1,024 (2¹⁰) in binary convention: 1 KB = 1,024 bytes, 1 MB = 1,048,576 bytes, 1 GB = 1,073,741,824 bytes. The SI convention uses powers of 1,000 (1 kB = 1,000 bytes), leading to the familiar discrepancy where a “500 GB” hard drive shows 465 GB in your operating system, both are correct, using different conventions. NIST’s official guide to the International System of Units states plainly that it is not acceptable to use “kilo” for 1,024 or “giga” for 1,073,741,824, and points to the IEC’s dedicated binary prefixes, kibi (Ki), mebi (Mi), and gibi (Gi), as the technically correct terms for these binary multiples.
Binary in Programming Languages
Most programming languages provide direct support for binary operations. In C, Java, Python, and JavaScript, bitwise operators manipulate individual bits: AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). Binary literals are prefixed with 0b in most languages: 0b1010 represents 10. Hexadecimal uses the 0x prefix: 0xFF represents 255.
Practical programming uses of binary operations include setting and clearing flag bits (permissions, feature flags), creating bitmasks for efficient storage of boolean arrays, implementing hash functions and checksums, performing fast multiplication/division by powers of 2 (left/right shift), implementing compression algorithms, and parsing binary file formats and network protocols. The calculator helps verify bitwise operation results during development and debugging.
Common Conversion Mistakes
- Reading binary right-to-left for place values but writing left-to-right for the number. Binary 1010 has the 1s in the 8 and 2 positions (reading right to left), giving 8+2=10, not 1+4=5, which would be the result of incorrectly reading left to right for place values.
- Forgetting carries in binary addition. 1+1=10 in binary, not 2. Every “10” result writes a 0 and carries a 1 to the next column.
- Confusing hex letters with decimal. The hex value “10” is decimal 16, not decimal 10. Always specify the base or use prefixes (0x10 for hex, 0b10 for binary).
- Ignoring signedness. In unsigned representation, 11111111₂ = 255. In signed (two’s complement), it’s -1. The calculator uses unsigned representation; programming languages vary.
Octal: The Unix Legacy System
Octal (base-8) uses digits 0–7, with each octal digit representing exactly 3 binary bits. While less common than hexadecimal in modern programming, octal remains important for Unix/Linux file permissions: the permission code 755 means rwxr-xr-x in binary (111 101 101 → owner has read/write/execute, group and others have read/execute). Understanding octal requires the same binary conversion skills this calculator develops.
3 Real-Life Examples
Three different situations, calculated the way the tool above does it.
| Situation | Mode & inputs | Result | What it means |
|---|---|---|---|
| Student verifying an IP octet for a subnetting exercise | Conversion mode: 192 (decimal) to binary. | 11000000 | Confirms the first octet of 192.168.1.1 matches the expected binary pattern before working through the rest of the subnet calculation by hand. |
| Developer converting a hex color code to check its brightness | Conversion mode: FF5733 (hexadecimal) to decimal. | 16,734,003 (binary: 111111110101011100110011) | Seeing the full binary breakdown makes it easy to isolate each 8-bit color channel (FF, 57, 33) for red, green, and blue individually, exactly what’s needed when debugging a color-manipulation function. |
| CS student practicing two’s complement by hand | Manual calculation: represent −18 in 8-bit two’s complement. | 18 = 00010010. Inverted = 11101101. Plus 1 = 11101110. | Working through each step (binary representation, bit inversion, adding 1) and then checking the final answer against the calculator’s own two’s complement handling confirms the manual process was done correctly before an exam or assignment. |
These are illustrative calculations using the same base-conversion logic the calculator above applies. They’re a learning and verification tool, not a substitute for a compiler, interpreter, or professional development environment for production code.
Important Notes
- This calculator handles unsigned integers by default. Negative arithmetic results are displayed using 32-bit two’s complement representation, always confirm this matches your target platform’s actual integer size and signedness before relying on a result for real code.
- Precision is exact up to 2⁵³−1. JavaScript’s native number type handles integers up to 9,007,199,254,740,991 with full precision, well beyond typical 32-bit or 64-bit programming and educational use cases.
- Division truncates toward zero. Binary division in this calculator performs integer division (no fractional or decimal remainder shown), matching how most low-level integer division operators behave.
- Input validation is strict per base. Binary fields only accept 0 and 1, octal only accepts 0 through 7, and hexadecimal accepts 0 through 9 and A through F, entering an invalid digit for the selected base will show an error rather than a guessed result.
- This tool is for education and verification, not production systems. Always test actual code against your specific language, compiler, and platform rather than relying solely on a calculator result for critical applications.
- Data privacy. All calculations run in your browser. Your inputs aren’t sent to a server, and the PDF is generated locally on your device.
Related Developer Tools
Frequently Asked Questions
Decimal to Binary Conversion: The Division Method
Converting from decimal to binary is one of the most fundamental skills in computer science, and the standard method, repeated division by 2, is straightforward once understood. Take the decimal number, divide it by 2, record the remainder (0 or 1), then divide the quotient by 2 again, repeating until the quotient reaches 0. The binary representation is the sequence of remainders read from bottom to top.
Worked example for decimal 42: 42÷2=21 r0; 21÷2=10 r1; 10÷2=5 r0; 5÷2=2 r1; 2÷2=1 r0; 1÷2=0 r1. Remainders bottom to top: 101010₂. Verification: 32+8+2=42 ✓. This method works for any non-negative integer. For large numbers, it’s tedious by hand: this is exactly what the calculator automates. Enter 42 in the conversion tab (decimal→binary) to see the instant result with the bit-level breakdown.
A faster mental shortcut is to find the largest power of 2 that fits, subtract, repeat. For 42: 32 fits (bit 5 = 1), remainder 10; 8 fits (bit 3 = 1), remainder 2; 2 fits (bit 1 = 1), remainder 0. Filling in the zeros: 101010. This “subtraction method” is faster for humans but equivalent mathematically to the division method.
Two’s Complement: Representing Negative Numbers in Binary
Standard (unsigned) binary can only represent non-negative numbers. To represent negative numbers, computers use two’s complement: a system where the most significant bit (MSB) indicates sign (0 for positive, 1 for negative) and negative numbers are stored as the bitwise complement plus one. In 8-bit two’s complement: +5 = 00000101; -5 = 11111011 (invert all bits to get 11111010, add 1 to get 11111011).
Two’s complement has an elegant property: binary addition works correctly for both positive and negative numbers without any special handling. Adding 5 and -5 in 8-bit two’s complement: 00000101 + 11111011 = 100000000. The carry-out beyond 8 bits is discarded, leaving 00000000: correct answer, 0. This is why processors use two’s complement universally, the same addition circuit handles both positive and negative integers.
The range of an N-bit two’s complement number is -2^(N-1) to 2^(N-1)-1. For 8-bit: -128 to +127. For 32-bit: approximately -2.1 billion to +2.1 billion. Understanding this range is critical for avoiding integer overflow bugs in programming, a common source of security vulnerabilities and crashes when arithmetic results exceed the representable range.
Bitwise Operations: AND, OR, XOR, NOT, and Shifts
Beyond arithmetic (add, subtract, multiply, divide), binary supports bitwise logical operations that operate on individual bits independently. These operations are fundamental to low-level programming, embedded systems, cryptography, and performance optimization.
AND (&): Each output bit is 1 only if both corresponding input bits are 1. Used for masking (extracting specific bits), clearing bits, and implementing subnet operations in networking. Example: 1010 AND 1100 = 1000.
OR (|): Each output bit is 1 if either input bit is 1. Used for setting bits (turning specific bits on). Example: 1010 OR 0101 = 1111.
XOR (^): Each output bit is 1 if the input bits are different. Used in encryption (XOR cipher), error detection (parity), checksums, and toggle operations. XOR has the unique property that A XOR B XOR B = A, applying XOR twice undoes the operation, which is the basis of many encryption schemes. Example: 1010 XOR 1100 = 0110.
NOT (~): Inverts every bit (0→1, 1→0). Also called the ones’ complement. Combined with adding 1, it creates two’s complement (negation). Example: NOT 1010 = 0101 (in 4-bit).
Left shift (<<): Shifts all bits left by N positions, filling with zeros on the right. Equivalent to multiplying by 2^N. Example: 0101 << 2 = 10100 (5 × 4 = 20). This is how processors implement fast multiplication by powers of 2.
Right shift (>>): Shifts all bits right by N positions. For unsigned numbers, fills with zeros on the left (logical shift). Equivalent to integer division by 2^N. Example: 1100 >> 2 = 0011 (12 ÷ 4 = 3).
Binary in Digital Electronics and Hardware
At the hardware level, all computation reduces to binary logic gates: physical circuits that implement AND, OR, NOT, and their combinations. A half adder (adding two single bits) requires just one XOR gate and one AND gate. A full adder (adding two bits plus a carry-in) uses two XOR gates, two AND gates, and one OR gate. Chain 32 full adders together and you have a 32-bit ripple-carry adder: the fundamental building block of a processor’s arithmetic logic unit (ALU).
Modern processors contain billions of transistors implementing increasingly sophisticated binary arithmetic circuits: carry-lookahead adders (faster than ripple-carry), Wallace tree multipliers (parallel multiplication), and barrel shifters (single-cycle shifts of any amount). Understanding binary arithmetic is understanding how these circuits work at the conceptual level, each step in the calculator’s arithmetic walkthrough corresponds to physical logic operations in real hardware.
Binary Encoding Systems: ASCII, Unicode, and Beyond
All text in computers is encoded as binary. ASCII (1963) uses 7 bits per character, representing 128 characters, the English alphabet (uppercase and lowercase), digits, punctuation, and control characters. ‘A’ = 01000001 (65), ‘a’ = 01100001 (97), ‘0’ = 00110000 (48). Extended ASCII uses 8 bits (256 characters) to include accented European characters.
Unicode extended this to support every writing system on Earth. UTF-8, the dominant Unicode encoding, uses 1–4 bytes per character: ASCII characters use 1 byte (backward compatible), European accented characters use 2 bytes, Asian characters use 3 bytes, and emoji use 4 bytes. The binary representation of text is visible in hex editors, network packet captures, and data file analysis, all contexts where binary calculator skills apply.
Colour encoding follows the same principle. In RGB, each colour channel (Red, Green, Blue) uses 8 bits (0–255), making each pixel 24 bits. White = 11111111 11111111 11111111 = #FFFFFF. Red = 11111111 00000000 00000000 = #FF0000. Understanding the binary-hex relationship makes colour codes intuitive rather than arbitrary, each pair of hex digits is one 8-bit colour channel.
Practical Applications: Where You’ll Use Binary Skills
- Debugging bitwise code. When your bitmask operation produces unexpected results, stepping through the binary values column by column (exactly as this calculator shows) reveals the error.
- Network administration. Subnetting, CIDR notation, and firewall rules all involve binary manipulation of IP addresses and masks. System administrators who think fluently in binary subnet faster and troubleshoot more effectively.
- Embedded programming. Microcontrollers, IoT devices, and hardware interfaces (GPIO, SPI, I2C) use register-level programming where individual bits control hardware functions. Setting bit 3 of a register to enable a peripheral requires binary fluency.
- Security and CTF competitions. Capture-the-flag cybersecurity competitions frequently involve binary analysis, hex dumps, XOR ciphers, and bit manipulation challenges. Binary calculator skills are directly tested.
- Technical interviews. Many software engineering interviews include binary and bitwise questions, particularly at systems-level companies (hardware, embedded, infrastructure, security). Fluency with binary arithmetic and conversion is an expected baseline.
Learning Binary: A Progressive Approach
For students and self-learners, building binary fluency follows a natural progression. Start with the powers of 2: memorise 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 until they’re as automatic as the multiplication table. These are the binary place values, and knowing them instantly makes all conversions faster.
Next, practise binary-to-decimal conversion by reading binary numbers and summing the active bit positions. Start with 4-bit numbers (0000 through 1111 = 0 through 15), then 8-bit (0 through 255). The calculator’s bit visualization makes this tangible, you can see which positions are active and their corresponding values. Within a few hours of practice, reading simple binary numbers becomes nearly as fast as reading decimal.
Then practise decimal-to-binary conversion using the subtraction method (find the largest power of 2 that fits, subtract, repeat). Convert random numbers throughout your day, your phone battery percentage, the current temperature, page numbers in a textbook. Each conversion takes only seconds once the skill is developed, and it builds the intuitive feel for binary that makes programming, networking, and systems work more natural.
Finally, practise binary arithmetic, start with simple addition (4-bit numbers), then tackle subtraction with borrowing, multiplication, and division. The calculator serves as both a practice tool (work it out on paper first, then verify) and a reference tool (check specific calculations during real work). Most computer science programs expect students to perform 8-bit binary arithmetic by hand in exams, practising with the calculator builds this skill efficiently.
Number System Quick Reference
| Decimal | Binary | Hex | Octal | Notes |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | Zero, all bits off |
| 1 | 0001 | 1 | 1 | Smallest positive |
| 7 | 0111 | 7 | 7 | Max 3-bit / octal digit |
| 8 | 1000 | 8 | 10 | First 4-bit number |
| 10 | 1010 | A | 12 | First hex letter |
| 15 | 1111 | F | 17 | Max 4-bit / hex nibble |
| 16 | 10000 | 10 | 20 | First 5-bit number |
| 127 | 01111111 | 7F | 177 | Max signed 8-bit |
| 255 | 11111111 | FF | 377 | Max unsigned 8-bit |
| 256 | 100000000 | 100 | 400 | First 9-bit number |
This reference table covers the most commonly encountered values in programming, networking, and hardware. Memorising the 4-bit values (0–15 = binary 0000–1111 = hex 0–F) provides the building blocks for reading and writing any binary or hexadecimal value by grouping into nibbles. The 8-bit boundary values (127 for signed max, 255 for unsigned max, 256 for overflow) are critical for understanding integer limits and avoiding overflow bugs in software development.
Calculate binary values now
Arithmetic, conversions, bit visualization: binary, decimal, hex, and octal in one developer tool.
Calculate binary ↑