Binary Calculator

Free binary calculator: add, subtract, multiply, divide, and do bitwise AND, OR, XOR and shifts, plus convert between binary, octal, decimal, and hex.

https://hexacalculator.com/calculators/other/computers/binary-calculator

Other

Computers

Binary Calculator

Free binary calculator: add, subtract, multiply, divide, and do bitwise AND, OR, XOR and shifts, plus convert between binary, octal, decimal, and hex.

Binary Calculator

Binary calculator

Choose whether to calculate with two binary numbers or convert one number between bases.

First number in decimal
Second number in decimal
Result in octal

Result in every base

Binary: 10110

Octal: 26

Decimal: 22

Hexadecimal: 16

Each binary digit and the decimal value it contributes

Position

Power

Bit

Value (decimal)

42^4116
32^300
22^214
12^112
02^000
Loading calculator…

The Binary Calculator tool processes numbers represented in base 2. This is a notation used in digital circuits. By entering two binary numbers, addition, subtraction, multiplication, division and bitwise logical operations can be performed. Also, a number can be converted between binary, octal, decimal and hexadecimal representation. All results are shown in the four different numeral systems so that the results can be read off if desired.

What is binary representation?

Binary representation is a positional numeral system with base 2. While the decimal system we use in everyday life has ten digits from 0 to 9, the binary system only has two digits: 0 and 1. Each of these individual digits is called a bit.

Computers are based on binary representation because it can be directly implemented in hardware. Circuits only need to distinguish between two states (on and off) rather than ten different levels as with a decimal machine. This simplicity allows almost all digital devices to store and transmit information as bit sequences.

How do place values work?

Just like each digit in the decimal system represents a power of ten, each digit in the binary system represents a power of two. When reading a binary number from right to left, each place represents 1, 2, 4, 8, and 16 respectively, and so on. Let's take the binary number 10010 as an example.

100102=(1×24)+(0×23)+(0×22)+(1×21)+(0×20)=1810010_2 = (1 \times 2^4) + (0 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (0 \times 2^0) = 18

To convert a decimal number to binary, subtract the largest possible power of two and repeat this process for the remaining value. Any place used is noted with a 1 while all others are noted with a 0. The examples below show some conversions that should help you intuitively understand the concept.

Decimal

Binary

Octal

Hexadecimal

2

10

2

2

8

1000

10

8

10

1010

12

A

16

10000

20

10

255

11111111

377

FF

Binary arithmetic

Addition, subtraction, multiplication and division follow the same principles as in the decimal system but differ in that carry-over and underflow bases are 2 instead of 10.

If the sum of a column is two, there will be a carry. The bitwise rules are as follows: if you add 0 to 0, you get 0; if you add 0 to 1, you get 1; if you add 1 to 1, you get 0 and carry 1 to the next column.

10102+11002=101102(10+12=22)1010_2 + 1100_2 = 10110_2 \qquad (10 + 12 = 22)

The "subtracting 1 from 0" requires a borrow. The digit that is borrowed from becomes a 2, and the digit that was borrowed from is reduced by 1. If the result is negative, this calculator will add a minus sign in front of the binary number and display the result in signed format.

Multiplication is done by shifting and adding. Since each bit-value can only be a 0 or a 1, each line of the long multiplication is either a left shift of the first number or a zero.

101112×112=10001012(23×3=69)10111_2 \times 11_2 = 1000101_2 \qquad (23 \times 3 = 69)

Division is performed according to the base 2 algorithm, returning both a quotient and remainder. This calculator displays both the quotient and remainder, as well as giving the exact decimal quotient.

Bitwise Operations

Bitwise operations compare two numbers bit by bit. This is a method to set flags in software, mask fields or shift bits. AND returns 1 only if both bits at one position are 1. OR returns 1 if either of the bits is 1. XOR returns 1 if the two bits differ. Left Shift moves all bits up and doubles the value with each shift. Right Shift halves the value.

a

b

a AND b

a OR b

a XOR b

0

0

0

0

0

0

1

0

1

1

1

0

0

1

1

1

1

1

1

0

Octal and hexadecimal systems

In the octal system bits are grouped in threes and in hexadecimal they're grouped in fours. This allows both systems to concisely represent long binary numbers. In hexadecimal, the digits 0 through 9 are used, followed by A through F for values ten through fifteen. Because these characters can't be entered into normal input fields, this tool doesn't accept hexadecimal input but will always display the result in hexadecimal along with the other number systems.

Here's how to use this calculator.

At the top select mode. In calculation mode enter two binary numbers and choose an operation. The result is shown in binary, octal, decimal or hexadecimal representation with also breakdown of place values. In conversion mode enter a number and tell the calculator which numeral system to use to see its representation in different numeral systems. If the number contains digits not allowed in that numeral system then the calculator will point this out in a note.

Frequently asked questions

How do you add two binary numbers?

Starting from the right, add digits. If a column of digits adds up to two, carry one over to the next column. The rules for addition are: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0, and carry one over to the next column. For example: if you add 1100 to 1010, you get 10110, which is equal to adding 12 to 10 in decimal, or 22.

How do you convert a binary number to decimal?

Multiply each bit value by its corresponding place (i.e., a power of two), and add the results. Reading from right to left, this gives us: (0x1) + (1x2) + (0x4) + (1x8) = 10.

Can this calculator handle hexadecimal numbers?

Although the results are also shown in hexadecimal representation, since letters A through F cannot be entered into the input field, hexadecimal inputs will not be accepted. Please enter numbers either in binary, octal or decimal system and check the results in hexadecimal representation.

What are the functions of bitwise operations AND, OR and XOR?

These operations compare two numbers bitwise. AND will retain a 1 only if both bits in the compared position are 1s; OR retains a 1 if either of the bits in the compared position is a 1; and XOR retains a 1 only if one of the bits in the compared position is 0, but not both.

Why do computers use binary instead of decimal?

For the binary system only hardware that can distinguish between two states (on and off) is required. In contrast, to realize ten different levels for the decimal system in a circuit would be much more complex and less reliable.

Related calculators

Disclaimer: This calculator is provided for general informational and educational purposes only. Our calculators are under active development, and results may be inaccurate, incomplete, or unsuitable for your situation. Always verify the figures independently and seek advice from a qualified professional before relying on them. We make no warranties and accept no liability for any loss or decision arising from use of this tool.

References

  1. MDN: Bitwise operators

    Reference for AND, OR, XOR, and shift operations on integers.

  2. Encyclopaedia Britannica: Binary number system

    Overview of base-2 notation and its role in computing.