Binary Arithmetic Calculator
Add, subtract, multiply, or divide two binary numbers. Column workings and decimal equivalents shown.
Number Base Converter
Convert any number between binary, decimal, hexadecimal, and octal. Enter in any field to convert to all others.
Bitwise Operations
AND, OR, XOR, NOT on two binary values. Bit-by-bit truth table shown.
Binary to Decimal
Enter a binary number to see its decimal value with full positional breakdown.
Decimal to Binary
Enter a decimal integer to see its binary representation using repeated division by 2.
The Binary Number System
The binary system uses base 2 with only the digits 0 and 1. Each digit is called a bit. Each position in a binary number represents a power of 2, starting at 2⁰ (= 1) on the right and increasing to the left.
Converting Decimal to Binary
Divide the decimal number by 2 repeatedly. Record the remainder (0 or 1) at each step. Read the remainders from the last division to the first - that is the binary representation.
Binary Place Values
| Bit Position | Power | Value | Binary Example |
|---|---|---|---|
| 0 (rightmost) | 2⁰ | 1 | 00000001 |
| 1 | 2¹ | 2 | 00000010 |
| 2 | 2² | 4 | 00000100 |
| 3 | 2³ | 8 | 00001000 |
| 4 | 2⁴ | 16 | 00010000 |
| 7 (MSB of byte) | 2⁷ | 128 | 10000000 |
Binary Arithmetic Rules
Addition
Column-by-column from right to left. Four basic cases:
Subtraction
Same column process, but borrow from the left when subtracting 1 from 0. Borrowing converts a 0 to 10 (two) in the current column, allowing the subtraction to proceed. Each borrow reduces the column to the left by 1.
Multiplication
Long multiplication with shifts. Each bit of the multiplier either produces 0 (multiply by 0) or copies the multiplicand (multiply by 1), shifted left by that bit's position. Sum all partial products.
Division
Long division as in decimal. At each step, determine whether the divisor fits into the current partial dividend: if yes write 1 and subtract; if no write 0 and bring down the next bit. The remainder is what's left after all bits are processed.
Bitwise Operations
Bitwise operations apply a logical function to every corresponding pair of bits in two numbers. They work at the individual bit level and form the foundation of low-level programming, hardware design, and cryptography.
| A | B | AND | OR | XOR | NAND | NOR | XNOR |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
Practical Uses of Bitwise Operations
- AND (masking): Isolate specific bits. value AND 0x0F extracts the lower 4 bits (nibble) of any byte. Used in IP address subnet masking.
- OR (setting bits): Turn specific bits on. value OR 0x80 sets the most significant bit. Used to enable flags in a bitmask register.
- XOR (toggling / encryption): Flip specific bits. A XOR A = 0 (any value XORed with itself is zero). XOR with a key produces a simple cipher. XOR is also used in parity checking and error detection.
- NOT (complement): Flips every bit. In two's complement systems, the negative of a number is NOT(n) + 1. For a signed 8-bit number, NOT(00000001) = 11111110, and 11111110 + 1 = 11111111 = -1.
- Left shift (<<): Multiplies by 2 per shift. n << 1 = 2n. Used in fast multiplication and constructing bitmasks.
- Right shift (>>): Divides by 2 per shift (floor division). Used in fast division and extracting high-order bits.
Hexadecimal and Octal
Hexadecimal (Base 16)
Hexadecimal uses digits 0 to 9 and letters A to F, where A=10, B=11, C=12, D=13, E=14, F=15. Each hex digit represents exactly 4 bits (one nibble), making conversion between binary and hex straightforward: group bits into fours from the right and convert each group.
Hex is used everywhere in computing: memory addresses, colour codes (#FF5733), assembly language, byte dumps, and network protocol analysis. Two hex digits always represent one byte (8 bits), so a 32-bit integer maps to 8 hex digits.
Octal (Base 8)
Octal uses digits 0 to 7. Each octal digit represents exactly 3 bits. Unix/Linux file permissions use octal: 755 = 111 101 101 in binary, meaning owner has read-write-execute (7), group has read-execute (5), others have read-execute (5).