Skip to content

Programmer Calculator

Do integer math in hex, decimal, octal or binary with bitwise operators and shifts. Results wrap like a real 8, 16, 32 or 64-bit register, signed or unsigned.

Result64-bit signed
HEX10F5
DEC4,341
OCT10365
BIN0001 0000 1111 0101
BitsClick a bit to flip it
60
56
52
48
44
40
36
32
28
24
20
16
12
8
4
0
Operators, from highest to lowest precedence
( )Grouping
- ~Negate, bitwise NOT
* / %Multiply, divide (rounds toward zero), remainder
+ -Add, subtract
<< >> >>>Shift left, arithmetic shift right, logical shift right
&AND
^XOR
|OR
0x 0o 0bHex, octal and binary prefixes work in any input mode. Use _ to group digits.

Last reviewed:

What is a programmer calculator?

A programmer calculator works with integers the way a computer stores them: as a fixed number of bits in a register. It shows the same value in hexadecimal, decimal, octal and binary at once, and supports bitwise operators that ordinary calculators lack: AND (&), OR (|), XOR (^), NOT (~) and shifts (<<, >>, >>>). These are everyday tools for reading flags and bit masks, permissions, colour values, network addresses, protocol headers, hardware registers and hash values.

Word size matters because real integers overflow. An 8-bit register holds 256 different patterns. Interpreted as unsigned, they are 0 to 255. Interpreted as signed using two's complement, the representation used by virtually all modern hardware and by Java, C#, Go and Rust, they are −128 to 127: the top bit stands for −128 instead of +128. So the bit pattern 1111 1111 is 255 unsigned and −1 signed, and 127 + 1 in a signed 8-bit register wraps around to −128. Bugs caused by this, such as a counter going negative or a size check passing when it should fail, are hard to spot without seeing the bits.

This calculator evaluates expressions using arbitrary-precision integers (JavaScript BigInt) and then wraps every intermediate result to the selected word size, exactly as an 8, 16, 32 or 64-bit register would. Unlike JavaScript's own bitwise operators, which work on 32-bit values, it handles full 64-bit values without losing precision.

How to use this tool

  1. Choose the Input base: HEX, DEC, OCT or BIN. It sets how plain numbers are read. Prefixes always work: 0x1F, 0o17 and 0b1010 are read correctly in any mode, and _ can group digits, as in 1_000_000.
  2. Choose the Word size (8, 16, 32 or 64 bits) and whether values are Signed.
  3. Type an expression such as 0xFF & ~0b1010 | 1 << 12. The result appears as you type, in HEX, DEC, OCT and BIN, each with a Copy button. Copied values include their prefix (0x, 0o, 0b) except decimal.
  4. Use the Bits grid to see every bit of the result, numbered from bit 0 on the right. Click a bit to flip it; the expression is replaced by the new value.
  5. Switching the input base converts a single number into the new base. Longer expressions are left as they are.
  6. The operator reference lists precedence from highest to lowest: grouping, unary minus and NOT, multiply/divide/remainder, add/subtract, shifts, AND, XOR, OR.

Examples

Setting and clearing bits

The default expression, in 64-bit signed mode:

0xFF & ~0b1010 | 1 << 12

HEX  10F5
DEC  4,341
OCT  10365
BIN  0001 0000 1111 0101

~0b1010 clears bits 1 and 3 from 0xFF, giving 0xF5, and | 1 << 12 sets bit 12. Because & binds tighter than | and shifts bind tighter than both, no parentheses are needed, but adding them makes intent clearer.

Overflow and signedness

Expression        Word, mode          HEX          DEC
-1                8-bit signed        FF           -1
-1                8-bit unsigned      FF           255
127 + 1           8-bit signed        80           -128
255 + 1           8-bit unsigned      00           0
0x7FFFFFFF + 1    32-bit signed       8000 0000    -2,147,483,648
0xDEADBEEF        32-bit signed       DEAD BEEF    -559,038,737
0xDEADBEEF        32-bit unsigned     DEAD BEEF    3,735,928,559

The bits never change between signed and unsigned; only their interpretation does. 0x7FFFFFFF + 1 is the classic Java and C int overflow.

Arithmetic versus logical shift, and extracting a byte

-8 >> 1                      32-bit signed   FFFF FFFC   -4
-8 >>> 1                     32-bit signed   7FFF FFFC   2,147,483,644
(0x12345678 >> 8) & 0xFF     32-bit          0056        86

>> copies the sign bit into the vacated positions, so negative numbers stay negative. >>> fills with zeros, as in Java and JavaScript. Shifting right by 8 and masking with 0xFF extracts the second-lowest byte, 0x56.

Common errors and how to fix them

  • Unexpected "f". Switch the input to HEX or write 0x before hex numbers. Letters A-F are not digits in decimal mode. Use 0xff or switch to HEX input.
  • Unexpected "*". There is no power operator, so 2 ** 3 is rejected. Use a shift for powers of two: 1 << 3 is 8.
  • Division by zero. Both / and % by zero are errors.
  • A closing ")" is missing. and The expression ends too early. Check that parentheses balance and that the expression does not end with an operator such as 1 +.
  • Cannot shift by a negative amount. Shift counts must be zero or positive.
  • Surprising negative results. In signed mode, any value with the top bit set is negative. Untick Signed to see the unsigned value of the same bits.
  • Division results look truncated. Integer division rounds toward zero, as in C, Java and Go: -7 / 2 is −3 and -7 % 2 is −1.

When developers use this

  • Decoding a flags field or status register from documentation, a packet capture or a log, bit by bit.
  • Building or checking bit masks for permissions, feature flags or enum sets.
  • Reproducing integer overflow behaviour from Java, C or Go code to understand a bug.
  • Converting colour values, Unix file permissions (0o644 is 420) or memory addresses between bases.
  • Extracting bytes or fields from packed integers with shifts and masks.
  • Checking two's complement representations when writing parsers for binary formats.

Privacy and how it works

All evaluation happens in your browser with JavaScript BigInt. Each intermediate result is wrapped with BigInt.asIntN or BigInt.asUintN to the chosen width. Nothing you type is sent anywhere.

Limitations

  • Integers only: there are no floating-point numbers, fractions or IEEE 754 views.
  • Shifting by the word size or more gives 0. Java, C# and x86 hardware instead mask the shift count, so in Java 1L << 70 equals 1L << 6, which is 64. In C the result is undefined.
  • There is no power, rotate or bit-count operator, and no memory or history.

FAQ

What is two's complement?

It is the standard way to store signed integers. A negative number −n is stored as the bit pattern of 2^bits − n, so in 8 bits −1 is 1111 1111 and −128 is 1000 0000. Its advantage is that addition and subtraction work identically for signed and unsigned values.

Why do results change when I switch word size?

Every intermediate result is wrapped to the selected width. A value that fits in 64 bits may overflow in 16 bits, and the high bits are discarded, just as they would be in a 16-bit register.

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

>> is an arithmetic shift: it fills the new top bits with copies of the sign bit, so it divides signed numbers by two, rounding toward minus infinity. >>> is a logical shift that always fills with zeros, treating the value as unsigned.

How do I check if a bit is set?

AND the value with a mask containing only that bit: value & (1 << n) is non-zero if bit n is set. For example, 0b1010 & (1 << 3) is 8, so bit 3 is set.

Why is octal useful?

Mainly for Unix file permissions, where each octal digit encodes the read, write and execute bits for user, group and others. 0o755 is 111 101 101 in binary: rwx for the owner, r-x for everyone else.

Can I enter negative numbers in hex?

Write a minus sign before the number, as in -0x10, or enter the two's complement pattern directly. In 16-bit signed mode, 0x8000 is −32,768.

Why does NOT 0 show 65,535?

~0 sets every bit. In 16-bit unsigned mode, that is FFFF, or 65,535. In signed mode the same bits read as −1.

Guides