Arithmetic in the Bases Computers Use
A programmer calculator differs from a scientific one in what it treats as fundamental. It works in binary, octal, decimal and hexadecimal at once, showing the same value in every base simultaneously, and it offers bitwise operations, AND, OR, XOR, NOT and shifts, that manipulate individual bits rather than the number as a whole.
That combination is what makes it useful for reading a permission mask, checking a colour value, or working out why a shift produced an unexpected result.
How to Use the Programmer Calculator
The word size setting is the one that changes results silently, so it is worth checking before anything else.
- Choose the word size, 8, 16, 32 or 64 bits. This decides where values wrap and how NOT behaves, and is the most common source of surprising results.
- Enter a value in whichever base is convenient. The other three update immediately, which is the fastest way to convert.
- Use the bitwise operators for masks and flags: AND to test or clear bits, OR to set them, XOR to toggle them.
- Use shifts to multiply or divide by powers of two. A left shift by one doubles the value; a right shift halves it, discarding the bit that falls off the end.
- Watch for overflow. A value that exceeds the word size wraps around rather than growing, which is exactly what happens in a fixed-width integer in real code.
Why Word Size Changes the Answer
NOT is the clearest demonstration. In 8-bit, NOT 0 is 255. In 16-bit it is 65,535, and in 32-bit it is 4,294,967,295. The operation is identical, invert every bit, but the number of bits differs, so the result does too. Any calculation involving NOT, or any value that crosses the top of the range, depends on this setting.
Shifts have the same sensitivity. Shifting left pushes bits off the top of the word and they are gone, so 0x80 shifted left by one is 0x100 in 16-bit but 0x00 in 8-bit. This is not a quirk of the calculator; it is precisely what happens to a fixed-width integer in C, Java or Rust, which is why matching the word size to the type you are debugging matters.
Bitwise Operations
What each operator does and the job it is usually reached for.
| Operator | Effect | Typical use |
|---|---|---|
| AND (&) | 1 only where both bits are 1 | Test a flag, clear bits with a mask |
| OR (|) | 1 where either bit is 1 | Set flags without disturbing others |
| XOR (^) | 1 where the bits differ | Toggle bits, simple checksums |
| NOT (~) | Inverts every bit | Build an inverse mask |
| << (left shift) | Multiplies by 2 per position | Fast multiplication, build masks |
| >> (right shift) | Divides by 2 per position | Fast division, extract bit fields |
AND with a mask is how you read part of a packed value: an RGB colour 0xFF8800 gives its green channel as (value >> 8) & 0xFF. That pattern, shift into position, then mask, is the most common idiom in bit manipulation.
Bases in Everyday Development
Hexadecimal dominates because each digit maps to exactly four bits, so a byte is always two hex digits and the boundary is visible at a glance. Binary shows individual bits but becomes unreadable past a byte or two. Octal survives mainly in Unix file permissions, where each digit conveniently encodes read, write and execute for one class of user.
That is why chmod 755 means what it does: 7 is 111 in binary, granting read, write and execute to the owner, while 5 is 101, granting read and execute to group and others. Seeing the octal and binary side by side in a calculator makes the mapping obvious in a way the decimal 493 never does.