All Tools

Binary Calculator: Add, Subtract, AND, OR, XOR, Shift

Add, subtract, multiply and divide binary or hex numbers of any length, and apply AND, OR, XOR, NAND, NOR, NOT, shifts, rotations, bit counts and shuffles. Results in binary, hex and decimal. Nothing is uploaded.

Number system
Bit width

Enter values to see the result in binary, hex and decimal.


About the binary calculator

This page adds, subtracts, multiplies and divides binary numbers and applies every common bitwise operation: AND, OR, XOR, NAND, NOR, XNOR and NOT, shifts, rotations, bit reversal, bit counts and shuffles. Switch the number system to Hex to do the same with hexadecimal values. Every result is shown in binary, hex and decimal, each with its own Copy button. Values may be up to 10,000 digits long and the arithmetic is exact. Everything is calculated in your browser, and your numbers never leave your device.

How to use it

Steps

  1. Choose Binary or Hex, then pick an Operation. Add is selected to start.
  2. For a two-value operation, type the first value (A) and the second value (B). The decimal value of each appears under its field.
  3. For a one-value operation such as NOT, shift or rotate, type one value per line. Each line gets its own result, in the same order.
  4. Set the Bit width when it matters: 8, 16, 32 or 64 bits, or Input length, which uses the digits you typed, leading zeros included.
  5. Press Copy next to the binary, hex or decimal result you need.

Operations

Arithmetic

Addition, subtraction, multiplication and division are exact at any length and never overflow. A negative difference is shown with a minus sign, for example 0011 − 0101 = −10, together with its two's complement at the chosen width: 1110 in 4 bits or 11111110 in 8 bits. Division gives the whole-number quotient and the remainder, so 1101 ÷ 11 is 100 remainder 1.

Bitwise logic

AND, OR and XOR compare the two values bit by bit. NAND, NOR and XNOR are their inverses, so they depend on the width: at the input width, 1100 NAND 1010 is 0111. NOT inverts every bit inside the width, so 101 becomes 010 at its own length and 11111010 at 8 bits. A value wider than a fixed width is refused rather than cut short.

Shifts, rotations and counts

Shift left moves bits towards the top and drops the ones that fall out. Shift right is logical by default, filling with zeros; turn on Arithmetic shift to copy the sign bit instead, as a signed integer would. Rotations move bits around the width so none are lost. Reverse flips the bit order, the two counts report how many 1 or 0 bits the value holds within the width, and Shuffle puts the bits in a random order using your browser's cryptographic generator.

Random values

Choose Random values to generate up to 1,000 random binary or hex strings of a fixed length, one per line, with an option to make every value unique.

Related tools

To change a value from one base to another, including octal and decimal, use the Number Base Converter. To turn text into its binary or hex bytes, use Text to Binary or Text to Hex. For random decimal numbers in a range, see the Random Number Generator. The Hex Calculator opens this page with the hex system selected.

Open-source credits

  • The calculator is written for this site. Its arithmetic uses JavaScript's built-in arbitrary-precision BigInt type from the ECMAScript standard, and two's complement follows the usual definition of a value modulo 2 to the power of the width.
  • Random values and shuffles use the browser's built-in Web Crypto API crypto.getRandomValues, with a Fisher-Yates shuffle as described by Donald Knuth in The Art of Computer Programming.
  • The tool uses no third-party library.

Frequently asked questions

How large can the numbers be?

Each value may have up to 10,000 binary or hex digits. The calculator works on JavaScript BigInt values, so addition, subtraction, multiplication and division are exact at any size and never round or overflow the way 32-bit or 64-bit integers do.

How are negative results shown?

A subtraction that goes below zero is shown with a minus sign, for example -10 in binary for minus two. The page also shows the two's complement bit pattern at the chosen bit width, which is how a computer would store the value. If the value needs more bits than the width allows, the page says so instead of wrapping silently.

What does the bit width setting change?

The width is the size of the register the bits live in. NOT, NAND, NOR, XNOR, shifts, rotations, reversal, bit counts and shuffles all work inside it, so inverting 101 at the input width gives 010, while at 8 bits it gives 11111010. Input length uses the number of digits you typed, leading zeros included.

What is the difference between a logical and an arithmetic right shift?

A logical right shift fills the vacated high bits with zeros. An arithmetic right shift copies the top bit, the sign bit in two's complement, so a negative number stays negative: 10010011 shifted right by two is 00100100 logically and 11100100 arithmetically.

Are the random values and shuffles truly random?

They come from your browser's cryptographic random number generator, crypto.getRandomValues, with rejection sampling so that no digit is favoured. Every value is generated on your device and nothing is sent anywhere.

Can I process several values at once?

Yes. One-value operations such as NOT, shifts, rotations, reversal and bit counts accept one value per line and return one result per line in the same order. Blank lines are skipped, and an invalid line is reported by its line number.

Other related tools