Number systems
| System | Base (radix) | Digits used |
|---|---|---|
| Binary | 2 | 0, 1 |
| Octal | 8 | 0–7 |
| Decimal | 10 | 0–9 |
| Hexadecimal | 16 | 0–9 and A(10), B(11), C(12), D(13), E(14), F(15) |
Computers use binary because electronic circuits have two stable states (ON = 1, OFF = 0). The value of a digit depends on its position (place value = baseposition).
Conversions
Decimal → any base
Divide repeatedly by the base and write the remainders from bottom to top. Example: 25 → binary: 25/2 = 12 r1, 12/2 = 6 r0, 6/2 = 3 r0, 3/2 = 1 r1, 1/2 = 0 r1 → 11001.
For a decimal fraction, multiply by the base and take the integer parts from top to bottom: 0.625 × 2 = 1.25 → 1; 0.25 × 2 = 0.5 → 0; 0.5 × 2 = 1.0 → 1 → 0.101.
Any base → decimal
Multiply each digit by its place value and add. 1011012 = 32 + 0 + 8 + 4 + 0 + 1 = 45. 1A16 = 1×16 + 10 = 26. 178 = 1×8 + 7 = 15.
Binary ↔ octal / hexadecimal (shortcut)
Group binary digits from the right: 3 bits = 1 octal digit, 4 bits = 1 hex digit. 1101012 → 110 101 → 658. 110101102 → 1101 0110 → D616.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 8 | 1000 | 10 | 8 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | FF |
Binary arithmetic
- Addition rules: 0+0 = 0, 0+1 = 1, 1+1 = 10 (0 carry 1), 1+1+1 = 11.
- Subtraction: 10 − 1 = 1 (borrow). Multiplication is like decimal: 1×1 = 1, otherwise 0.
- 1's complement: flip every bit (0↔1). 2's complement = 1's complement + 1. Computers store negative integers in 2's complement and subtract by adding the 2's complement.
- The leftmost bit of a signed number is the sign bit (0 = positive, 1 = negative). With n bits, unsigned numbers range from 0 to 2n − 1 (8 bits: 0–255).
- MSB = most significant (leftmost) bit; LSB = least significant (rightmost) bit.
Character codes
- ASCII – American Standard Code for Information Interchange; 7-bit, 128 characters. 'A' = 65, 'a' = 97, '0' = 48, space = 32. Extended ASCII uses 8 bits (256 characters).
- EBCDIC – Extended Binary Coded Decimal Interchange Code; 8-bit code used by IBM mainframes.
- Unicode – universal code for the scripts of all languages, including Odia, Hindi and emoji. Common encodings: UTF-8 (variable 1–4 bytes, used on the web), UTF-16, UTF-32.
- BCD (Binary Coded Decimal) – each decimal digit stored as 4 bits: 59 → 0101 1001.
- Gray code – consecutive numbers differ in only one bit. Excess-3 – BCD + 3.
- Parity bit – extra bit added for simple error detection (even or odd parity).
Logic gates and Boolean algebra
Logic gates are electronic circuits that work on binary inputs. Boolean algebra was developed by George Boole.
| Gate | Output is 1 when… | Symbol |
|---|---|---|
| AND | all inputs are 1 | A·B |
| OR | at least one input is 1 | A+B |
| NOT (inverter) | input is 0 (one input only) | A′ or Ā |
| NAND | NOT of AND – output 0 only when all inputs are 1 | (A·B)′ |
| NOR | NOT of OR – output 1 only when all inputs are 0 | (A+B)′ |
| XOR | inputs are different | A⊕B |
| XNOR | inputs are the same | A⊙B |
NAND and NOR are universal gates – any other gate can be built using only NAND (or only NOR). A two-input gate has 2² = 4 rows in its truth table; n inputs give 2n rows.
De Morgan's laws: (A+B)′ = A′·B′ and (A·B)′ = A′+B′. Other rules: A+0 = A, A·1 = A, A+A = A, A·A′ = 0, A+A′ = 1.
Quick recall: base 2/8/10/16 · 3 bits = 1 octal digit · 4 bits = 1 hex digit · F = 15 · ASCII 7-bit, 128 chars · Unicode covers all scripts · NAND, NOR universal · XOR = 1 when inputs differ.