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.