What Are Number Bases?
A number base (or radix) defines how many unique digits a counting system uses. The familiar decimal system uses 10 digits (0–9). But computers, networking, and programming rely on other bases — binary, octal, and hexadecimal — because they map more naturally to how digital hardware works.
The Four Main Number Systems
Decimal (Base 10)
Digits: 0–9. The system humans use for everyday counting. Each position represents a power of 10.
42 = (4 × 10¹) + (2 × 10⁰) = 40 + 2 = 42
Binary (Base 2)
Digits: 0 and 1. The language of computers — every bit in memory, every transistor state is binary. Each position represents a power of 2.
1011 (binary) = (1×8) + (0×4) + (1×2) + (1×1) = 11 (decimal)
Common uses: CPU registers, bitwise operations, file permissions (chmod 755), network masks.
Octal (Base 8)
Digits: 0–7. Each octal digit maps to exactly 3 binary bits, making it a compact representation. Prefix: 0o in Python/JS, leading 0 in C/C++.
0o17 (octal) = (1×8) + (7×1) = 15 (decimal)
Unix permissions: chmod 755 → rwxr-xr-x
Hexadecimal (Base 16)
Digits: 0–9 and A–F (where A=10, B=11, … F=15). Each hex digit represents exactly 4 binary bits (a "nibble"), so a full byte fits in just 2 hex digits. Prefix: 0x.
0xFF = (15×16) + 15 = 255 (decimal) = 11111111 (binary)
Web color: #FF5733 → R=255, G=87, B=51
Common uses: memory addresses, web colors, MAC addresses, cryptographic hashes, byte-level data.
How to Convert Between Bases
Decimal → Binary
Divide by 2 repeatedly and read remainders from bottom to top:
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Read upward: 13 = 1101 (binary)
Binary → Decimal
Multiply each bit by its positional power of 2 (right to left), then add:
1101 = (1×8) + (1×4) + (0×2) + (1×1) = 13
Hex → Decimal
Replace A–F with 10–15, then multiply by powers of 16:
0x1F = (1×16) + (15×1) = 31
Binary → Hex (shortcut)
Group binary digits in sets of 4 from the right, convert each group to a hex digit:
1111 0011 → F 3 → 0xF3 = 243
Practical Uses by Field
| Field | Base Used | Why |
|---|---|---|
| Web design | Hex (16) | Color codes (#RRGGBB) |
| Unix/Linux | Octal (8) | File permissions (chmod) |
| Networking | Binary + Decimal | IP addresses, subnet masks |
| Debugging | Hex (16) | Memory addresses, byte values |
| Cryptography | Hex (16) | Hash outputs (SHA-256, MD5) |
| Low-level / embedded | Binary (2) | Bit flags, hardware registers |
Bitwise Operations Quick Reference
Bitwise operators work on individual binary bits and are essential in systems programming:
&(AND) — both bits must be 1:1100 & 1010 = 1000|(OR) — at least one bit is 1:1100 | 1010 = 1110^(XOR) — bits differ:1100 ^ 1010 = 0110<<(left shift) — multiply by 2ⁿ:1 << 3 = 8>>(right shift) — divide by 2ⁿ:16 >> 2 = 4
Common Programmer Values to Memorize
- 0xFF = 255 — maximum unsigned byte
- 0x7F = 127 — maximum signed byte
- 0x80 = 128 — minimum negative signed byte (two's complement)
- 0xFFFFFFFF — maximum 32-bit unsigned integer (4,294,967,295)
- 0b10000000 = 128 — most significant bit of a byte
Frequently Asked Questions
Why do computers use binary?
Electronic circuits have two stable states: on (1) and off (0). Binary maps directly to this physical reality — it's the most reliable and noise-resistant way to represent data in hardware. All other number systems used in computing (hex, octal) are just human-readable shortcuts for binary.
When should I use hex instead of binary?
Use hex when you need to read or write binary data compactly. A 32-bit value takes 32 characters in binary but only 8 in hex. Memory dumps, color values, cryptographic hashes, and network packets are almost always displayed in hex for this reason.
What is base 36 used for?
Base 36 uses digits 0–9 and letters A–Z, making it the most compact alphanumeric encoding. It's used for short URL tokens, case-insensitive IDs, and compact serial numbers — anywhere you want a short, readable identifier from a large number.
How do I handle fractions in other bases?
Fractional conversions use negative powers of the base (e.g. 0.1 in binary = 0.5 in decimal, 0.1 in hex = 1/16 in decimal). Note that many decimal fractions (like 0.1) have no exact binary representation — this is the root cause of floating-point precision issues in programming.