Number bases
Decimal uses ten digits (0–9). Binary uses two (0 and 1), octal eight (0–7) and hexadecimal sixteen (0–9 and A–F). 255 in decimal is 1111 1111 in binary and FF in hex. Each hex digit stands for exactly four binary digits, which is why programmers like hex: it's a short way to write bits.
Signed numbers and two's complement
In a signed number the top bit marks a negative. Computers store negatives in two's complement: flip every bit and add 1. In 8 bits, −1 is 1111 1111 (FF) and the range is −128 to 127; unsigned, the same 8 bits run from 0 to 255. If an answer doesn't fit in the word size, it wraps around, just like in a real program, and Calcist tells you when that happens.
Bitwise operations
- AND keeps a 1 only where both numbers have one: 1100 AND 1010 = 1000.
- OR keeps a 1 where either has one: 1100 OR 1010 = 1110.
- XOR keeps a 1 where they differ: 1100 XOR 1010 = 0110.
- NOT flips every bit.
- Shift left by n multiplies by 2ⁿ; shift right divides by 2ⁿ and rounds down.