Everyday Life · General Mathematics
Number Base Converter
Converts any integer between the four most common number bases: binary (base-2), octal (base-8), decimal (base-10), and hexadecimal (base-16).
Calculator
Formula
N₁₀ is the decimal (base-10) equivalent of the number. dᵢ is the digit at position i (counted from the right, starting at 0). b is the source base (2 for binary, 8 for octal, 16 for hexadecimal). Each digit is multiplied by the base raised to the power of its position, and the products are summed. To convert from decimal to a target base, repeatedly divide the decimal value by the target base and record the remainders in reverse order.
Source: Knuth, D.E. — The Art of Computer Programming, Vol. 2: Seminumerical Algorithms (3rd ed.), Addison-Wesley, 1997.
How it works
Every number system uses a base (or radix) that defines how many unique digits exist. Decimal — the everyday system — uses base 10 with digits 0–9. Binary (base 2) uses only 0 and 1, making it ideal for digital electronics where a bit is either off or on. Octal (base 8) uses digits 0–7 and was historically common in early computing as a compact way to represent binary groups of three. Hexadecimal (base 16) uses digits 0–9 plus letters A–F and groups binary digits in fours, making it the dominant shorthand in programming, color codes (e.g. #FF5733), and memory addressing.
The universal conversion algorithm works via decimal as an intermediate step. To convert from any source base to decimal, each digit dᵢ at position i (indexed from the right, starting at 0) is multiplied by the base raised to the power of i, and the results are summed: N₁₀ = Σ dᵢ × bⁱ. For example, binary 1101 = 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13. To convert from decimal to a target base, divide the decimal number by the target base repeatedly, collecting remainders. Reading the remainders from last to first gives the result in the new base.
In practice, hexadecimal appears constantly in web development (#RGB colors), Linux file permissions use octal (chmod 755), and binary is the native language of all digital logic. Understanding base conversion helps debug low-level code, understand network subnet masks, interpret CPU registers in a debugger, and work with bitwise operations in any programming language.
Worked example
Suppose you want to convert the decimal number 255 into all other common bases.
Decimal to Binary: Divide 255 by 2 repeatedly and record remainders: 255 ÷ 2 = 127 R 1, 127 ÷ 2 = 63 R 1, 63 ÷ 2 = 31 R 1, 31 ÷ 2 = 15 R 1, 15 ÷ 2 = 7 R 1, 7 ÷ 2 = 3 R 1, 3 ÷ 2 = 1 R 1, 1 ÷ 2 = 0 R 1. Reading remainders bottom to top: 11111111.
Decimal to Octal: 255 ÷ 8 = 31 R 7, 31 ÷ 8 = 3 R 7, 3 ÷ 8 = 0 R 3. Result: 377.
Decimal to Hexadecimal: 255 ÷ 16 = 15 R 15 (F), 15 ÷ 16 = 0 R 15 (F). Result: FF.
Verify: Binary 11111111 = 1×2⁷ + 1×2⁶ + 1×2⁵ + 1×2⁴ + 1×2³ + 1×2² + 1×2¹ + 1×2⁰ = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. ✓ This is why 0xFF is 255, the maximum value for an 8-bit byte, commonly seen in web color codes such as #FFFFFF (white).
Limitations & notes
This calculator handles non-negative integers only — it does not support fractional (floating-point) base conversions, which require a separate algorithm for the fractional part (multiply by the target base repeatedly instead of dividing). Very large integers may be subject to JavaScript's safe integer limit of 2⁵³ − 1 (9,007,199,254,740,991 in decimal), beyond which precision may be lost. For hexadecimal input, enter digits 0–9 and A–F only; this converter does not validate invalid digit characters for a given base (e.g. entering digit '9' in binary will produce an incorrect result). Signed (negative) numbers and two's complement representation are not handled here — use a dedicated two's complement calculator for those scenarios.
Frequently asked questions
Why is hexadecimal so commonly used in programming?
Hexadecimal (base 16) is popular because it maps cleanly to binary: each hex digit represents exactly 4 binary bits (a nibble). This means an 8-bit byte is always exactly 2 hex digits (00 to FF), a 32-bit integer is 8 hex digits, and so on. This compact, human-readable representation makes it far easier to read memory dumps, color codes, and CPU registers than raw binary.
What is the difference between octal and hexadecimal?
Octal (base 8) groups binary digits in sets of 3 and uses digits 0–7. Hexadecimal (base 16) groups binary digits in sets of 4 and uses digits 0–9 plus A–F. Because modern computers process data in multiples of 8 bits (bytes), hexadecimal aligns more naturally with byte boundaries and has largely replaced octal in modern computing. Octal is still used for Unix/Linux file permission codes (e.g. chmod 755).
How do I convert a hexadecimal number like 1A3F to decimal?
Apply the positional formula: 1×16³ + A(10)×16² + 3×16¹ + F(15)×16⁰ = 4096 + 2560 + 48 + 15 = 6719. Remember that A=10, B=11, C=12, D=13, E=14, F=15. Enter 1A3F in this calculator with source base set to Hexadecimal to verify instantly.
Can this calculator convert numbers with decimal points (fractional bases)?
No — this calculator handles non-negative whole integers only. Fractional base conversion (e.g. converting 3.14 from decimal to binary) requires a different algorithm: the integer part is converted using repeated division, while the fractional part is converted by repeatedly multiplying by the target base and extracting the integer portion of each result. This process can sometimes produce infinitely repeating fractions in the target base.
What are some real-world uses of binary and hex that a developer would encounter daily?
Developers encounter binary and hex constantly: bitwise operations (flags, masks, permissions) use binary logic; HTML/CSS color codes are 6-digit hex values (e.g. #1E90FF for dodger blue); IPv4 subnet masks like 255.255.255.0 are often written as 0xFFFFFF00; debuggers display memory in hex; Unicode code points are written in hex (U+1F600); and file format magic bytes (e.g. PDF starts with 25 50 44 46 in hex) are always hex-encoded.
Last updated: 2025-01-15 · Formula verified against primary sources.