Whether you're debugging code, working with computer memory, or just curious about how computers think, understanding number bases is essential. This interactive guide will teach you everything about converting between binary, decimal, hexadecimal, and octal number systems — with live calculators, animated charts, step-by-step breakdowns, and popular tools for two's complement, IEEE 754 floats, Base64, Roman numerals, and more.
We use decimal (base-10) in everyday life because we have ten fingers, but computers think in binary (base-2) because they work with on/off electrical signals. Different bases serve different purposes in computing: hexadecimal (base-16) makes binary more readable, octal (base-8) simplifies Unix file permissions, and each has its place in modern technology.
Binary (Base-2): Uses 0 and 1 — the language of computers
Octal (Base-8): Uses 0–7 — common in Unix/Linux permissions
Decimal (Base-10): Uses 0–9 — our everyday number system
Hexadecimal (Base-16): Uses 0–9 and A–F — perfect for colors and memory addresses
Enter a number in any base and instantly see it expressed in all four common bases plus any custom base. The converter updates live as you type, validates your input against the chosen base, and shows the step-by-step arithmetic.
Binary is the foundation of all digital computing. Each digit (bit) represents a power of 2. When you convert binary to decimal, you're essentially adding up powers of 2 wherever there's a 1 in the binary number. Click any bit below to toggle it and watch the decimal value update live.
// Convert binary to decimal
const binaryToDecimal = (binary) => parseInt(binary, 2);
console.log(binaryToDecimal('101010')); // Output: 42
// Convert decimal to binary
const decimalToBinary = (decimal) => decimal.toString(2);
console.log(decimalToBinary(42)); // Output: "101010"
Enter a binary number or click the bits to toggle them. Each bit's power of 2 is shown below it.
Perform arithmetic operations directly in different number bases without converting to decimal first. Essential for understanding bitwise operations and how computers calculate at the register level.
Hexadecimal is everywhere in computing — from RGB color codes (#FF5733) to memory addresses (0x7fff5fbff8c0). One hex digit represents exactly four binary digits, making it a compact way to represent binary data.
#FF5733 = rgb(255, 87, 51)
Each pair represents R, G, B values
0x7fff5fbff8c0
Compact representation of memory locations
SHA-256 hashes in hex
e3b0c44298fc1c149afbf4c8996fb924…
Colors in web development use multiple base systems. RGB uses decimal (0–255), hex uses base-16, and HSL uses degrees and percentages. Paste any HEX, RGB, or HSL color and see every representation at once.
HEX: #FF5733
RGB: rgb(255, 87, 51)
HSL: hsl(11, 100%, 60%)
Binary: 11111111 01010111 00110011
Integer: 16734003
Computers store negative numbers using two's complement, a clever encoding that lets the same hardware adder handle both positive and negative values. For an N-bit number, positive values use their normal binary representation, and negative values are formed by inverting the bits of their absolute value and adding 1. This converter shows you the full story.
Modern computers store real numbers using the IEEE 754 standard. A 32-bit float splits its bits into three fields: 1 sign bit, 8 exponent bits, and 23 mantissa bits. Enter any number to see its exact binary representation and learn why 0.1 + 0.2 ≠ 0.3.
A quick reference showing the same values across different number bases. Notice the patterns — binary gets long quickly, while hex stays compact.
| Decimal | Binary | Octal | Hexadecimal | Common Use |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | Null / False |
| 1 | 0001 | 1 | 1 | True / LSB |
| 8 | 1000 | 10 | 8 | Nibble high bit |
| 15 | 1111 | 17 | F | Max 4-bit (nibble) |
| 16 | 10000 | 20 | 10 | One hex digit overflow |
| 127 | 1111111 | 177 | 7F | Max signed 8-bit (int8) |
| 128 | 10000000 | 200 | 80 | Min signed 8-bit (−128) |
| 255 | 11111111 | 377 | FF | Max byte (uint8) |
| 256 | 100000000 | 400 | 100 | 2⁸, one byte+1 |
| 1,023 | 1111111111 | 1777 | 3FF | Max 10-bit value |
| 1,024 | 10000000000 | 2000 | 400 | 1 KiB |
| 4,095 | 111111111111 | 7777 | FFF | Max 12-bit value |
| 65,535 | 1111111111111111 | 177777 | FFFF | Max uint16 |
Charts tell the story of why we use the bases we do. The first chart shows how many digits each base requires to represent growing numbers — hex stays compact while binary balloons. The second shows information density (bits per digit), and the third visualizes the exponential weight of each position in a 16-bit binary number.
Understanding base conversion isn't just academic — it's practical knowledge used daily by developers, network engineers, and system administrators.
Web Development: Converting hex color codes to RGB values for CSS manipulation
Network Engineering: Understanding IP addresses and subnet masks in binary
System Administration: Setting Unix file permissions using octal notation (chmod 755)
Embedded Systems: Working with hardware registers and bit manipulation
Cryptography: Reading and writing hash values in hexadecimal
Data Science: Optimizing memory usage and understanding data types
# Python examples of base conversion
binary_num = '101010'
decimal = int(binary_num, 2) # 42
hex_color = 'FF5733'
r = int(hex_color[0:2], 16) # 255
g = int(hex_color[2:4], 16) # 87
b = int(hex_color[4:6], 16) # 51
permission = 0o755 # chmod 755 = rwxr-xr-x
print(bin(permission)) # 0b111101101
While we've focused on integers, real numbers require special handling. Understanding decimal, binary, and hexadecimal representations of fractions reveals the precision limitations inherent in digital systems.
The infamous floating-point precision issue occurs because many decimal fractions cannot be exactly represented in binary. Just as 1/3 cannot be exactly represented in decimal (0.333…), 0.1 becomes an infinite repeating pattern in binary: 0.0001100110011…
This fundamental limitation affects all programming languages and is why financial systems often use decimal arithmetic libraries instead of native floating-point.
Understanding different bases transforms you from a code writer to a code detective. Here are real debugging scenarios where base conversion knowledge saves hours of frustration.
Addresses like 0x1234567F indicate misalignment. The last hex digit should be 0, 4, 8, or C for 4-byte alignment.
Quick check: Last hex digit in binary reveals alignment
Permission 755 in octal = 111 101 101 in binary
Each group of 3 bits = one permission set (rwx)
Instant read: 7 = rwx, 5 = r-x, 5 = r-x
CIDR /24 = 255.255.255.0 = 0xFFFFFF00
Count the 1s in binary to verify subnet size
Quick math: 32 − CIDR = host bits
// Common overflow bug - spot it using hex
uint8_t counter = 255; // 0xFF
counter++; // Overflow! Becomes 0x00
// Using hex makes the bug obvious
while (counter < 0x100) { // This condition is always true!
// uint8_t max is 0xFF, can never reach 0x100
process_data(counter++);
}
// Fix: Use larger type
uint16_t counter = 0xFF;
while (counter < 0x100) { // Now this works
process_data(counter++);
}
Once you think in binary, certain optimizations become obvious. These bitwise tricks are used in game engines, graphics programming, and embedded systems where every CPU cycle matters.
// Swap without temp variable
a = a ^ b; // a = 1010 ^ 1100 = 0110
b = a ^ b; // b = 0110 ^ 1100 = 1010 (original a)
a = a ^ b; // a = 0110 ^ 1010 = 1100 (original b)
// Count set bits (Brian Kernighan's algorithm)
int countBits(int n) {
int count = 0;
while (n) { n &= (n - 1); count++; }
return count;
}
// Round up to next power of 2
int nextPowerOf2(int n) {
n--;
n |= n >> 1; n |= n >> 2;
n |= n >> 4; n |= n >> 8;
n |= n >> 16;
return n + 1;
}
IP addresses are fundamentally binary but displayed in decimal dotted notation. Understanding the binary representation is crucial for subnetting and network configuration. This calculator handles every CIDR from /0 to /32, including the special /31 point-to-point and /32 host-route cases.
Character encoding bridges human-readable text and machine-readable numbers. Each character has representations in decimal, hex, binary, and octal. This works for any Unicode code point, not just 7-bit ASCII.
Base64 is not technically a number base — it's an encoding scheme that packs 3 bytes (24 bits) into 4 ASCII characters, using 64 printable symbols (A–Z, a–z, 0–9, +, /). It's how binary data hitchhikes through text-only channels like email, JSON, and data URIs.
Roman numerals are a base-10 hybrid that uses subtractive notation (IV = 4, IX = 9). Still seen on clocks, monarch names, Super Bowl numbers, and in book outlines. Supports numbers from 1 to 3,999.
Before computers popularized binary and hexadecimal, civilizations developed ingenious number systems based on practical needs. Many of these systems influence modern computing and timekeeping.
Still used in time (60 seconds, 60 minutes) and angles (360°)
Highly divisible: 60 has 12 factors
Used fingers AND toes for counting
Influenced Central American commerce systems
Subtractive notation: IV = 4, IX = 9
Still seen in clocks, book chapters, Super Bowl numbers
Some mathematicians argue base-12 would be better than base-10 for everyday use. With factors of 1, 2, 3, 4, 6, and 12, it makes division cleaner. In base-12, 1/3 = 0.4 exactly, 1/4 = 0.3 exactly, and 1/6 = 0.2 exactly. No repeating decimals!
The Dozenal Society actively promotes base-12, proposing digits 0–9 plus two new symbols (often X for ten and E for eleven).
While binary, octal, decimal, and hexadecimal are the most common, there are exotic number systems like negabinary (base −2), which can represent negative numbers without a sign bit. Useful in specialized signal processing and mathematical research.
Explore unusual number bases like base-3 (ternary), base-12 (duodecimal), or even negative bases. Converts in both directions.
A small live demo. This ticks every second, showing the current Unix timestamp (seconds since 1970-01-01 UTC) in binary, octal, decimal, and hexadecimal simultaneously.
Mental shortcuts to help you convert between bases quickly without a calculator:
Group binary digits in sets of 4. Each group converts to one hex digit.
Example: 1010 1111 = AF
Group binary digits in sets of 3. Each group becomes one octal digit.
Example: 111 101 101 = 755
Memorize: 2⁴=16, 2⁸=256, 2¹⁰=1024, 2¹⁶=65,536
These benchmarks help estimate conversions instantly.
FF = 255 (max), 80 ≈ 128 (half), 00 = 0 (min)
Estimate RGB values using these anchors.
Ready to practice more? Check out these specialized conversion tools on CountingMethods.com for different use cases:
Practice makes perfect. Choose a difficulty and test yourself. Easy sticks to 0–15, Medium expands to 0–255, and Hard covers 0–65,535 across all four common bases.
Understanding number bases opens up a deeper comprehension of how computers work at their core. Whether you're debugging hexadecimal memory dumps, setting octal file permissions, or optimizing binary operations, these conversion skills are fundamental to technical work.
The key to mastering base conversion is practice. Start with simple conversions between binary and decimal, then work your way up to hexadecimal. Soon, you'll be reading hex color codes and binary data as naturally as decimal numbers.
Remember: computers don't actually "think" in binary — they operate on electrical signals. Binary is just our human-readable representation of those on/off states. Each number base is simply a different lens through which we can view and manipulate the same underlying data, chosen for convenience in different contexts.