Skip to content

Category · 1 tool · 1 guide

Math and programming calculators

Programmers regularly do arithmetic that ordinary calculators handle badly. Reading a hex color or memory address, checking which bits a permission mask sets, working out what a negative number looks like in two's complement, or computing a network mask all require switching between number bases and thinking in fixed-width integers.

Mistakes in this area are subtle. An unsigned 32-bit value read as signed becomes negative, a right shift on a negative number behaves differently in Java and JavaScript, and an overflow in C wraps around silently. A desktop calculator in decimal mode cannot show you any of that, and doing it on paper is slow.

The tools in this category behave like real CPU registers: you choose the word size and signedness, and every result wraps exactly as it would in code. All calculations run in your browser using exact big-integer arithmetic, so 64-bit values are never rounded.

Tools in this category

Common tasks

Key concepts

Number base
Hexadecimal (base 16) writes each 4 bits as one digit, so a byte is exactly two hex digits. Binary shows individual bits, and octal is mostly seen in Unix file permissions like 0755.
Word size
Fixed-width integers hold 8, 16, 32 or 64 bits. Results that do not fit wrap around, so 255 + 1 in an unsigned 8-bit value is 0.
Two's complement
The way almost all CPUs store negative integers: invert the bits and add one. The top bit acts as the sign, so the 8-bit pattern 11111111 means -1 when signed and 255 when unsigned.
Bitwise operators
AND keeps bits set in both values, OR combines them, XOR keeps bits that differ and NOT flips all bits. They are used for flags, masks, hashing and low-level protocols.
Arithmetic vs logical shift
A logical right shift fills with zeros. An arithmetic right shift copies the sign bit, so negative numbers stay negative. JavaScript uses >>> and >> for the two.

Best practices

  1. Always state the word size and signedness when sharing a binary or hex value; the same bits mean different numbers.
  2. Use named constants for bit masks, such as FLAG_ADMIN = 1 << 3, instead of magic numbers.
  3. Remember that JavaScript bitwise operators work on 32-bit signed integers; use BigInt for 64-bit values.
  4. Check for overflow explicitly in languages that wrap silently, or use checked arithmetic helpers.
  5. Group long binary and hex literals with underscores, like 0xFFFF_FFFF, where your language allows it.

Guides