Why Computers Use Binary
Modern computers are built from transistors — semiconductor switches that can be either open (no current, representing 0) or closed (current flowing, representing 1). This two-state nature makes binary the natural number system for digital electronics. Using more than two states would require distinguishing between multiple voltage levels precisely and reliably, which becomes unreliable at the speeds and temperatures of real-world computing.
Every piece of data your computer handles — a text character, an image pixel, a floating-point number, a compiled instruction — is ultimately stored and processed as sequences of 1s and 0s. Binary is not just a convenience; it is the physical reality of how computation works.
Positional Notation Explained
All of the number systems discussed here use positional notation: the value of each digit depends on its position (its place value) as well as the digit itself. The base determines how many symbols are available and the multiplier for each position.
In any base b, reading a number from right to left, the positions represent b⁰, b¹, b², b³, and so on. The total value is the sum of each digit multiplied by its place value.
For example, the decimal number 437 means: (4 × 10²) + (3 × 10¹) + (7 × 10⁰) = 400 + 30 + 7 = 437.
Binary (Base 2)
Binary uses only two symbols: 0 and 1. Each binary digit is called a bit. Eight bits form a byte, which can represent 256 values (2⁸ = 256), ranging from 0 to 255.
Reading Binary Numbers
Each position from right to left represents a power of 2: 1, 2, 4, 8, 16, 32, 64, 128...
Example: 10110101 in binary = 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1 = 181 in decimal.
Binary in Programming
Many programming languages allow binary literals with a 0b prefix:
// JavaScript
const flags = 0b10110101; // 181
const mask = 0b00001111; // 15 (lower nibble mask)
// Python
value = 0b10110101 # 181
Octal (Base 8)
Octal uses eight symbols: 0 through 7. Each octal digit represents exactly three binary bits, which is why octal was popular in the early days of computing (when word sizes were multiples of 3 bits) and remains relevant for Unix/Linux file permissions.
Example: Octal 755 = (7 × 64) + (5 × 8) + (5 × 1) = 448 + 40 + 5 = 493 in decimal.
In C, C++, and many other languages, an integer literal starting with 0 (zero) is interpreted as octal: 0755 is not 755 — it is 493. This is a common source of bugs.
010 is 8, not 10. In JSON, leading zeros are forbidden entirely to avoid this ambiguity.
Decimal (Base 10)
Decimal uses ten symbols: 0 through 9. It is the system humans use naturally, almost certainly because we have ten fingers. From a computing perspective it is neither efficient nor natural — it is simply the interface layer between humans and machines.
Conversion from any other base to decimal is achieved by the positional notation formula: sum each digit multiplied by the base raised to its position.
Hexadecimal (Base 16)
Hexadecimal uses sixteen symbols: 0–9 and A–F (where A=10, B=11, C=12, D=13, E=14, F=15). Because 16 = 2⁴, one hex digit represents exactly four binary bits (a nibble), and two hex digits represent one byte. This compactness makes hex the preferred shorthand for binary data in computing.
Hex in CSS Colours
CSS colour codes use three pairs of hex digits representing red, green, and blue channels. #FF5733 decodes as: R = 0xFF = 255 (maximum red), G = 0x57 = 87, B = 0x33 = 51. Each channel is one byte (0–255).
Hex in Memory Addresses
Memory addresses are displayed in hexadecimal because they correspond directly to binary addresses. A 32-bit address like 0x7FFE0000 is more readable than its 32-digit binary equivalent: 0111 1111 1111 1110 0000 0000 0000 0000.
Hex in Cryptography
Cryptographic hash functions output raw bytes, conventionally displayed as hex strings. A SHA-256 hash produces 256 bits = 32 bytes = 64 hex characters. MD5 produces 128 bits = 32 hex characters. Visit the ToolMasta hash generator to see hex hash output in action.
Conversion Table: 0–16 in All Bases
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
Conversion Methods
Decimal to Any Base (Division Algorithm)
Repeatedly divide the decimal number by the target base. Record the remainder at each step. The remainders read from bottom to top give the result in the new base.
Example: 45 decimal to binary
- 45 ÷ 2 = 22 remainder 1
- 22 ÷ 2 = 11 remainder 0
- 11 ÷ 2 = 5 remainder 1
- 5 ÷ 2 = 2 remainder 1
- 2 ÷ 2 = 1 remainder 0
- 1 ÷ 2 = 0 remainder 1
Reading remainders bottom to top: 101101. Check: 32+8+4+1 = 45. Correct.
Binary to Hex (Grouping Method)
Group binary digits into sets of four (from right). Convert each group to its hex digit. Example: 11010110 → 1101 0110 → D 6 = 0xD6.
Binary to Octal (Grouping Method)
Group binary digits into sets of three (from right). Convert each group to its octal digit. Example: 11010110 → 11 010 110 → 3 2 6 = 0326.
Real-World Uses of Each Base
| Base | Name | Common Uses |
|---|---|---|
| 2 | Binary | CPU instruction sets, network protocol flags, bitwise operations, boolean logic, file bit flags |
| 8 | Octal | Unix/Linux file permissions (chmod 755), some legacy network protocols, C integer literals |
| 10 | Decimal | Human interface layer — display values, user input, accounting |
| 16 | Hexadecimal | CSS/HTML colour codes, memory addresses, hash outputs, Unicode code points, byte-level debugging |
Binary Bitwise Operations Overview
Bitwise operations manipulate individual bits within binary numbers. They are fundamental to low-level programming, networking, and performance-critical code.
The Four Core Bitwise Operators
- AND (&): Output bit is 1 only if both input bits are 1. Used for masking — extracting specific bits. Example:
0b1010 & 0b1100 = 0b1000(8) - OR (|): Output bit is 1 if either input bit is 1. Used for setting bits. Example:
0b1010 | 0b0101 = 0b1111(15) - XOR (^): Output bit is 1 if input bits differ. Used for toggling bits and simple encryption. Example:
0b1010 ^ 0b1100 = 0b0110(6) - NOT (~): Flips all bits. In most languages this also flips the sign bit, so ~5 = -6 (due to two's complement representation).
Bit Shifting
Left shift (<<) multiplies by 2 for each position shifted. Right shift (>>) divides by 2. These operations are faster than multiplication and division on most CPUs:
const x = 5; // 0b00000101
x << 1; // 10 (multiply by 2)
x << 2; // 20 (multiply by 4)
x >> 1; // 2 (divide by 2, floor)
For practical number base conversion without doing the maths manually, use the ToolMasta number base converter. You can also pair this with the colour converter to decode CSS hex colour values.
Try It Free — No Signup Required
Convert any number between binary, octal, decimal, and hexadecimal instantly. Supports both integer and floating-point values — no account required.
Open Number Base Converter