Number System Conversions
Computers use binary (base 2) internally; programmers often work with hexadecimal (base 16) as a compact binary representation. Decimal is what humans use daily.
Binary to Decimal
Method: multiply each bit by its positional power of 2, sum
1011₂ = 1×2³ + 0×2² + 1×2¹ + 1×2⁰
= 8 + 0 + 2 + 1 = 11₁₀
Decimal to Binary
Method: divide by 2, collect remainders (read upward)
25 ÷ 2 = 12 r1
12 ÷ 2 = 6 r0
6 ÷ 2 = 3 r0
3 ÷ 2 = 1 r1
1 ÷ 2 = 0 r1
25₁₀ = 11001₂
Hexadecimal
Hex digits: 0-9, A=10, B=11, C=12, D=13, E=14, F=15
1 hex digit = 4 binary bits
FF₁₆ = 1111 1111₂ = 255₁₀
A3₁₆ = 1010 0011₂ = 163₁₀
Decimal to hex: divide by 16, collect remainders
255 ÷ 16 = 15 r15 (F), 15 ÷ 16 = 0 r15 (F) → FF
Why Hex?
- Colours: #FF5733 = R255 G87 B51
- Memory addresses: 0x7FFE4B2A
- Two hex digits = one byte (8 bits)
- Much shorter than binary for large values
Convert number bases: Free Binary Converter
Binary–Decimal Quick-Reference Table
| Decimal | Binary | Hex | Octal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 5 | 0101 | 5 | 5 |
| 10 | 1010 | A | 12 |
| 15 | 1111 | F | 17 |
| 16 | 0001 0000 | 10 | 20 |
| 127 | 0111 1111 | 7F | 177 |
| 255 | 1111 1111 | FF | 377 |
| 1,024 | 0100 0000 0000 | 400 | 2000 |
How Binary–Decimal Conversion Works
Decimal to binary: repeatedly divide by 2, record the remainders, read upwards. 13 ÷ 2 = 6 r1; 6 ÷ 2 = 3 r0; 3 ÷ 2 = 1 r1; 1 ÷ 2 = 0 r1 → 1101. Binary to decimal: multiply each bit by its positional power of 2. 1101 = 1×8 + 1×4 + 0×2 + 1×1 = 13. Hexadecimal groups binary digits in sets of 4: 1111 1010 = FA in hex (F=15, A=10). Octal groups in sets of 3.
Binary is the native language of digital computers because electronic circuits reliably distinguish two voltage states (high/low, 1/0). A byte is 8 bits; values 0–255 (00000000–11111111 in binary, 00–FF in hex). IPv4 addresses are 32 bits (four 8-bit octets). Colour values in web design use hex: #FF5733 = R:255, G:87, B:51. Understanding binary arithmetic — AND, OR, XOR, NOT, bit shifts — is fundamental to low-level programming, networking, and cryptography.
Common Mistakes
- Reading binary right-to-left vs. left-to-right: The most significant bit (MSB) is on the left; the least significant bit (LSB) is on the right. 1000 = 8, not 1. Always write binary numbers with the highest power on the left.
- Confusing 0b prefix with the number: 0b1010 is the binary literal notation for decimal 10 (in programming languages like Python, JavaScript). The leading 0b is a prefix, not a digit.
- Signed vs. unsigned interpretation: 1111 1111 is 255 as an unsigned 8-bit integer, but −1 as a signed 8-bit integer (two's complement). Always specify whether a binary number is signed or unsigned when context matters.
Frequently Asked Questions
Physical components (transistors) reliably represent two stable states. Storing 10 distinct voltage levels for decimal would require much higher manufacturing precision and would be far more susceptible to noise. Binary logic gates (AND, OR, NOT) built from transistors can be combined into any arithmetic or logical operation — the entire architecture of modern CPUs emerges from billions of binary transistors switching at GHz speeds.
Two's complement represents negative integers by flipping all bits and adding 1. For 8-bit integers: −1 = 11111111, −128 = 10000000, +127 = 01111111. The advantage: addition works identically for positive and negative numbers using the same circuitry. The CPU doesn't need separate adder and subtractor circuits — it just adds. Also, there is only one representation of zero (unlike sign-magnitude which has +0 and −0).
A bit (binary digit) is the smallest unit: 0 or 1. A byte = 8 bits, representing values 0–255. A kilobyte (KB) = 1,024 bytes (IEC standard) or 1,000 bytes (SI standard) — the ambiguity is why kibibyte (KiB) was introduced for 1,024. Network speeds are measured in bits per second (Mbps); file sizes in bytes (MB). A 100 Mbps internet connection transfers 100/8 = 12.5 MB/s of data.