Developer & Security

Programmer Calculator

Do integer math the way a CPU does. Pick a word size of 8, 16, 32 or 64 bits, choose signed or unsigned, and calculate in hex, decimal, octal or binary with bitwise operations, shifts and rotates. Overflow is flagged and every result is shown in all four bases.

Free, runs in your browserUpdated October 2026
Word size
Numbers are
Input base
0x
0x
Bits of A (tap a bit to flip it)

Runs locally in your browser. Nothing you type is uploaded or stored.

Result
–

Integer math only. Division truncates toward zero and the remainder takes the sign of A, as in C, Java and JavaScript.

Programmer calculator diagram: 32-bit 0xDEADBEEF AND 0xFFFF gives 0xBEEF, which is 48,879 in decimal
How the Programmer Calculator works: Hex, decimal, octal and binary math with fixed word sizes and two's complement

How to Use the Programmer Calculator

How to use the programmer calculator: set word size and base, enter A, choose an operation and read the result in all bases
Numbered steps on the Programmer Calculator. Follow them in order.
  1. Pick the word size: 8, 16, 32 or 64 bits.
  2. Choose the base you type in: HEX, DEC, OCT or BIN.
  3. Enter value A, for example DEADBEEF. Its decimal value appears underneath.
  4. Choose an operation such as AND, XOR, a shift or a rotate, then enter B.
  5. Read the result, with hex, signed and unsigned decimal, octal and binary listed below and any overflow flagged.

Choose a word size of 8, 16, 32 or 64 bits and decide whether the numbers are signed (two’s complement) or unsigned. Pick the input base, type value A, choose an operation and type value B. The result appears in the base you are typing in, and the panel lists it in hex, signed and unsigned decimal, octal and binary, each with its own copy button.

Switching the base rewrites both values in the new base, so you can also use the tool as a converter. Tap any bit in the Bits of A grid to flip it, which is handy for building masks and flags. Prefixes such as 0x, 0o and 0b, spaces and underscores are accepted, and a minus sign enters a negative number in two’s complement form.

Two’s Complement and Word Size

A fixed-width register holds a value modulo 2n. In unsigned form the bits read as an ordinary binary number. In signed form the top bit has a negative weight, so a pattern whose top bit is set stands for its unsigned value minus 2n.

signed = unsigned − 2n   when the top bit is 1
−x = (NOT x) + 1    result = exact result mod 2n
Word sizeUnsigned rangeSigned range
8-bit (byte)0 to 255−128 to 127
16-bit (short)0 to 65,535−32,768 to 32,767
32-bit (int)0 to 4,294,967,295−2,147,483,648 to 2,147,483,647
64-bit (long)0 to 18,446,744,073,709,551,615−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

All math uses JavaScript BigInt, so 64-bit values are exact rather than rounded to the 53 bits of an ordinary floating point number.

Worked Example

The calculator opens with 32-bit signed hex: 0xDEADBEEF AND 0xFFFF. The mask keeps the low 16 bits, so the result is 0xBEEF, which is 48,879 in decimal, 137357 in octal and 0000 0000 0000 0000 1011 1110 1110 1111 in binary, with 13 bits set. Value A on its own has its top bit set, so as a signed 32-bit number it is 3,735,928,559 − 4,294,967,296 = −559,038,737.

A second example shows overflow. In 8-bit signed mode, 100 + 50 should be 150, but the largest signed byte is 127. The bits wrap to 1001 0110, which reads as 150 − 256 = −106, and the calculator flags a signed overflow. Switch to unsigned and the same bits read as 150, with no overflow.

Bitwise Operations and Shifts

OperationWhat it doesTypical use
AND1 where both bits are 1Masking, testing a flag
OR1 where either bit is 1Setting flags
XOR1 where the bits differToggling bits, checksums
NOTInverts every bitClearing with AND NOT
<< nMoves bits left, fills with 0Multiply by 2n
>> nMoves right, copies the sign bitSigned divide by 2n, rounding down
>>> nMoves right, fills with 0Unsigned divide by 2n
ROL, RORBits leaving one end re-enter at the otherHashes, ciphers

For example, in 16 bits 0x8000 >> 4 gives 0xF800 because the sign bit is copied, while 0x8000 >>> 4 gives 0x0800. Rotating 0x8000 left by one gives 0x0001.

Notes and Limits

  • Division truncates toward zero and the remainder takes the sign of the dividend, as in C, Java and JavaScript. Python’s // and % round toward negative infinity instead, so results differ for negative numbers.
  • Shifts by the word size or more give 0 (or all ones for an arithmetic shift of a negative number). In C that case is undefined behavior, so do not rely on it in code.
  • Signed overflow is flagged in signed mode, and carry or borrow in unsigned mode.
  • Only integers are supported. For arbitrary length hex math use the Hex Calculator.

Frequently asked questions

What is a programmer calculator?

It is a calculator for integer math in the number bases programmers use: hexadecimal, decimal, octal and binary. It works with fixed word sizes such as 32 bits and adds bitwise operations, shifts and two's complement signed numbers.

How do I convert a negative number to two's complement?

Choose the word size and DEC input, then type the number with a minus sign. The calculator shows its two's complement bits in hex and binary. By hand, invert every bit of the positive value and add 1.

What is the difference between >> and >>>?

>> is an arithmetic shift: it copies the sign bit into the empty positions, so negative numbers stay negative. >>> is a logical shift: it always fills with zeros, treating the value as unsigned.

Why does 127 + 1 give -128 in 8-bit signed mode?

The largest signed 8-bit value is 127, or 0111 1111. Adding 1 gives 1000 0000, and in two's complement that pattern means -128. The calculator flags this as a signed overflow.

Does the calculator handle 64-bit numbers exactly?

Yes. It uses JavaScript BigInt, so every 64-bit value up to 18,446,744,073,709,551,615 is exact. Ordinary JavaScript numbers lose precision above 2 to the power of 53.

How do I check whether a bit is set?

AND the value with a mask that has only that bit set, such as 0x8 for bit 3. A nonzero result means the bit is set. You can also read the Bits of A grid directly.