Binary Calculator

Advanced calculator for binary arithmetic, bitwise operations, and number system conversions. Perform calculations with binary, decimal, hexadecimal, and octal numbers.

0

Binary Arithmetic: Perform addition, subtraction, multiplication, and division with binary numbers.

1010 + 1101
1111 - 1010
110 × 101
1001 ÷ 11

Understanding Binary Numbers

Binary is a base-2 number system that uses only two digits: 0 and 1. Each digit in a binary number is called a bit (binary digit). Binary is the fundamental language of computers and digital systems.

Binary Place Values:

In binary, each position represents a power of 2:

... 2³ 2² 2¹ 2⁰ . 2⁻¹ 2⁻² ...

So the binary number 1011 represents: (1×2³) + (0×2²) + (1×2¹) + (1×2⁰) = 8 + 0 + 2 + 1 = 11 (decimal)

Binary Arithmetic Rules

Binary Addition
A B A + B (Carry, Sum)
0 0 0, 0
0 1 0, 1
1 0 0, 1
1 1 1, 0
1 1 (with carry 1) 1, 1
Binary Subtraction
A B A - B (Borrow, Difference)
0 0 0, 0
0 1 1, 1 (with borrow)
1 0 0, 1
1 1 0, 0

Bitwise Operations Explained

1

AND (&): Returns 1 only if both bits are 1. Used for masking (extracting specific bits).

1010 & 1100 = 1000 (bits 1 and 3 are 1 in both)

2

OR (|): Returns 1 if at least one bit is 1. Used for setting bits.

1010 | 1100 = 1110 (bits 1, 2, and 3 are 1 in at least one)

3

XOR (^): Returns 1 only if bits are different. Used for toggling bits.

1010 ^ 1100 = 0110 (bits 2 and 3 are different)

4

NOT (~): Inverts all bits (0 becomes 1, 1 becomes 0). Also called one's complement.

~1010 = 0101 (in an 8-bit system: ~00001010 = 11110101)

5

Left Shift (<<): Shifts bits to the left, filling with 0s. Equivalent to multiplying by 2ⁿ.

1010 << 2 = 101000 (shift left by 2 positions)

6

Right Shift (>>): Shifts bits to the right. For unsigned numbers, fills with 0s. Equivalent to dividing by 2ⁿ (integer division).

1010 >> 2 = 0010 (shift right by 2 positions)

Two's Complement Representation

Two's complement is a mathematical operation on binary numbers, and is the most common method of representing signed integers in computers.

To find the two's complement of a negative number:

  1. Write the positive version of the number in binary
  2. Invert all the bits (change 0 to 1 and 1 to 0)
  3. Add 1 to the result

Example: -5 in 8-bit two's complement:

1. +5 in binary: 00000101

2. Invert bits: 11111010

3. Add 1: 11111011 (this is -5 in two's complement)

Number Systems Comparison

Decimal Binary Hexadecimal Octal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 8 10
9 1001 9 11
10 1010 A 12
15 1111 F 17
16 10000 10 20
255 11111111 FF 377

Calculator Features:

  • Four operation modes: Arithmetic, Bitwise, Conversion, and Two's Complement
  • Supports binary, decimal, hexadecimal, and octal number systems
  • Visual bitwise operation visualization
  • Step-by-step two's complement conversion
  • Binary bit visualization with place value explanation

Frequently Asked Questions

Binary is used in computers because electronic circuits can easily represent two states (on/off, high voltage/low voltage) as 1 and 0. This makes binary the most reliable and efficient system for digital electronics. Transistors, the building blocks of modern computers, naturally operate as switches with two states.

One's complement simply inverts all bits (0 becomes 1, 1 becomes 0). Two's complement inverts all bits and then adds 1. Two's complement is preferred in computer systems because it eliminates the problem of having two representations for zero (positive zero and negative zero) that occurs with one's complement, and it simplifies arithmetic operations.

Binary fractions work like decimal fractions but with powers of 2 instead of 10. For example, binary 0.101 represents (1×2⁻¹) + (0×2⁻²) + (1×2⁻³) = 0.5 + 0 + 0.125 = 0.625 in decimal. Each position after the binary point represents 2⁻¹ (0.5), 2⁻² (0.25), 2⁻³ (0.125), etc.

For unsigned integers: 2ⁿ - 1. For example, 8 bits can represent numbers from 0 to 255 (2⁸ - 1 = 255).
For signed integers using two's complement: -2ⁿ⁻¹ to 2ⁿ⁻¹ - 1. For example, 8 bits can represent numbers from -128 to 127.

Hexadecimal (base-16) is more compact than binary. One hexadecimal digit represents exactly 4 binary digits (bits), making it easier for humans to read and write binary values. For example, the 8-bit binary number 11011011 can be written more concisely as DB in hexadecimal. This is especially useful when working with memory addresses, color codes, and machine-level programming.