Binary Calculator

Perform arithmetic and bitwise operations on binary numbers. Results are shown in binary, decimal, hexadecimal, and octal.

Input

= 10 (decimal)
= 6 (decimal)
Step-by-step
  0001010
+ 0000110
  0010000

Results

1010 + 0110 =
10000
binary result
BaseResult
Binary (2)10000
Decimal (10)16
Hex (16)10
Octal (8)20

Binary Reference

DecimalBinaryHex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

NOR of 1010 and 0110 is 0001 in four bits, 11110001 in eight bits and sixty leading ones followed by 0001 in 64 bits. The inputs never changed; only the width did. That is the surprise hiding in every inverted-bit operation, and it is why this page has a Bit width list that appears whenever you pick AND, OR, XOR, NOR or XNOR. Arithmetic needs no such setting, so the page treats the two families differently, and the sections below show how.

Why the width matters, shown on 1010 and 0110

Start with the values the page loads: A = 1010 (decimal 10) and B = 0110 (decimal 6). Add gives 10 + 6 = 16, shown as 10000 with hex 10 and octal 20. Multiply gives 60, shown as 111100 (hex 3C, octal 74). Divide gives the integer quotient 1 and the note "Integer quotient; remainder 100 (binary)", because 10 = 1 x 6 + 4 and 4 is 100 in binary.

Subtract is where the sign shows up. 1010 - 0110 is 100 (decimal 4), but use 1010 - 1111 instead and the page prints -101 (decimal -5), with a note that in 4-bit two's complement the same value would be 1011. The Step-by-step panel lines up the absolute values and puts a minus sign in front of the answer row. The two's complement figure is simply 2 to the power of the width, plus the negative result: 16 - 5 = 11, which is 1011. Larger magnitudes move the note to 8, 16 or 32 bits, the first width with room for a sign bit.

The five logic operations compare bits column by column and never carry. With Auto width the page pads to the longer input, here four bits. AND = 0010 (2), OR = 1110 (14), XOR = 1100 (12). NOR is NOT(A OR B), so it inverts the OR result inside the chosen width: 1110 becomes 0001 (1). XNOR inverts XOR: 1100 becomes 0011 (3). Pick 8-bit and the same NOR reads 11110001, which is 241 in decimal, hex F1, because the four extra leading zeros of OR flip to ones.

A shortcut check for any width w: NOR(A, B) = 2^w - 1 - (A OR B). At four bits that is 15 - 14 = 1; at eight bits it is 255 - 14 = 241.

Bitwise results are labelled "unsigned" under the big binary figure because no sign bit is applied. If either input needs more bits than the width you picked (11111 needs five bits, so 4-bit fails), the page shows an error and asks for a wider width or Auto. Values are held as arbitrary-size integers, so a 33-bit input is exact rather than clipped, and each box accepts up to 256 digits.

How to Use This Calculator

  1. Type the first number into First Binary Number (A). Only 0 and 1 are accepted, and the decimal equivalent appears underneath it.
  2. Choose the Operation from the list: Add, Subtract, Multiply, Divide, AND, OR, XOR, NOR or XNOR.
  3. Type the second number into Second Binary Number (B). There is no Calculate button; the Results card refreshes after every keystroke.
  4. For a bitwise operation, set Bit width. Auto uses the longer of your two inputs; 4, 8, 16, 32 and 64-bit are the fixed options. NOR and XNOR give different answers at different widths.
  5. Read the large binary figure, then the Binary, Decimal, Hex and Octal rows. For Add and Subtract, also check the Step-by-step panel.
  6. If a box is empty you see "Enter a binary number for A (use only 0s and 1s)" or the same message for B. Dividing by 0 shows "Division by zero".

Frequently Asked Questions

Can I enter 25 and get its binary form?

No. Both boxes accept only the digits 0 and 1, so other keys are ignored. The page converts binary in, decimal, hex and octal out. For decimal to binary, divide by 2 repeatedly and read the remainders from last to first: 25 gives 11001.

A negative result shows a minus sign. Is that two's complement?

No, it is a sign plus magnitude, such as -101 for -5. The note under the result gives the two's complement pattern for the smallest standard width that can hold it, which is 1011 at four bits. Use that pattern if you are writing it into a register or an exercise.

Which width should I choose for NOR and XNOR?

The width of the register or data type you are modeling: 8 for a byte, 32 or 64 for common integer sizes. Auto only matches the longest number you typed, which is right for a textbook exercise written at a fixed number of bits and wrong for anything else.

What happens to the remainder in division?

The quotient is cut off toward zero and the remainder appears in a note below the answer in binary. For 1010 divided by 0110 the quotient is 1 and the note says remainder 100. Fractions are never produced.

Is there a limit on how many bits I can enter?

Each box takes up to 256 digits, and the arithmetic is exact at that size. Bitwise results are padded to the chosen width, so a 256-bit input needs Auto or a width that covers it, and the 64-bit option rejects anything wider.