What does a binary calculator do?
It performs arithmetic and bitwise operations on numbers written in binary, and shows the result in binary, octal, decimal and hexadecimal at the same time. Each operand can be entered in any of those bases, so you can add a hex value to a binary one without converting by hand first.
The arithmetic side covers addition, subtraction, multiplication, division and remainder. The bitwise side covers AND, OR and XOR, which combine two operands bit by bit, along with NOT, which flips every bit, and the left and right shifts. Those operations are not a curiosity: masking, flag sets, colour channels, IP addresses and network prefixes are all bit patterns rather than quantities, and bitwise arithmetic is the natural way to work with them.
Because the machine's word size is what makes binary arithmetic wrap around, the result is also shown at 8, 16, 32 and 64 bits, in both the unsigned and the two's complement reading. A value that looks like a large positive number at 64 bits can be a small negative one at 8, and seeing both readings side by side is usually the quickest way to understand a value that came out of a program.
How to use the binary calculator
- Enter the first operand, then choose the base it is written in using the bin, oct, dec and hex buttons beneath the box.
- Enter the second operand and its base. It is ignored for NOT, which takes a single value.
- Pick an operation from the list: the four arithmetic ones, remainder, AND, OR, XOR, the two shifts, or NOT.
- Read the result in binary, hexadecimal, octal and decimal, each grouped for legibility.
- Look at the width table below. It gives the unsigned and the signed reading of the result at 8, 16, 32 and 64 bits.
- Note the reminder under the result when you divide or use NOT: division reports the remainder, and NOT is shown as 64-bit two's complement, since inverting an arbitrary-precision integer is negative by definition.
Binary Calculator limits and rules
| Item | Limit |
|---|---|
| Input bases | Binary, octal, decimal and hexadecimal, chosen per operand |
| Prefixes | A leading 0b, 0o or 0x is accepted and stripped |
| Arithmetic | Add, subtract, multiply, divide with remainder, and modulo |
| Bitwise | AND, OR, XOR, NOT, shift left and shift right |
| Precision | Exact integer arithmetic, with no floating-point rounding |
| Widths shown | 8, 16, 32 and 64 bits, unsigned and two's complement signed |
| Division | Integer division, with the remainder reported separately |
| Shift rule | Shifts follow JavaScript semantics on the 64-bit value shown |
When to use it
- Adding or subtracting values you have in binary without converting them by hand first.
- Applying a bit mask to see which flags survive an AND.
- Working out the two's complement reading of a byte that came out of a program as a large positive number.
- Converting a hex value to decimal and checking the arithmetic at the same time.
- Checking what a left or right shift by a given amount does to a value.
Is it private?
Every calculation is done with JavaScript integers in this page. Nothing is sent to a server, stored or logged, and the tool keeps working if the network drops after the page has loaded.
Frequently asked questions
Because binary arithmetic is modular, and the modulus is the width of the field the value lives in. A byte holding 255 and given one more does not produce 256; it wraps to 0 and sets a carry. The same sixteen bits mean 65535 in an unsigned 16-bit field and minus one in a signed one. Since the number alone does not say how wide the field is, the tool shows the reading at each common width, and the one you want is whichever matches the machine that produced the value.
It is the way signed integers are represented: the leftmost bit of a word carries a negative weight, so in eight bits 1111 1111 is minus one rather than 255. The advantage is that addition and subtraction need no special case — the same circuit adds 1 and 1111 1111 and gets 0, exactly as it would for the values 1 and minus 1 — which is why it displaced the older sign-and-magnitude and one's complement schemes. Its one cost is asymmetry: the most negative value in a width has no positive counterpart.
Because NOT inverts every bit of an arbitrary-precision integer, and in two's complement the inverse of a value is its negation minus one. So NOT 0 is minus one and NOT 5 is minus six. On a fixed-width machine the result is the same bits, just read within that width; in 8-bit terms NOT 0000 0101 is 1111 1010, which is 250 unsigned and minus six signed. That is why the width table matters more than usual for this operation, and why the tool notes that it shows the 64-bit reading.
Differently in ways that surprise people. A right shift of a negative value moves the sign bit down, so the value stays negative and moves towards zero — it is an arithmetic shift rather than a logical one, and it rounds down rather than towards zero. A left shift simply multiplies by a power of two and can overflow, which at a fixed width discards the highest bits. When you need to move bits through an unsigned field, mask the value to the width first so the sign bit cannot interfere.
The arithmetic is exact arbitrary-precision integer arithmetic, so addition, multiplication and the bitwise operations are correct far beyond 64 bits. The width table, though, is about how a fixed-width machine would read the value, and 64 bits is the widest common word size, so that is where it stops. Values that exceed 64 bits are still calculated and converted correctly; they simply have no single-machine reading in the table. If you need a wider field, the binary and hex outputs are the exact ones to read.
The base conversion part is, but the bitwise operations and the width table are not usually there. Most calculator applications let you switch display between bases; fewer offer AND, OR, XOR and shifts, and fewer still show you what the result means as a signed value at each common width. Those two things are what this tool is for. For arithmetic on quantities rather than bit patterns, a general calculator is the better choice, since round-off and decimal fractions are outside what integer arithmetic here will do.
Related tools
Written and maintained by Md. Nur Hossain Repon.