Number Base Converter
Convert numbers between binary, octal, decimal and hexadecimal.
Reviewed by Aygul Dovletova · Last reviewed
Using the Number Base Converter
- Click an input base - Binary (2), Octal (8), Decimal (10), or Hexadecimal (16) - to tell the tool which numeral system you are typing.
- Type your number. The input field filters keystrokes so only digits valid for the selected base are accepted; pasting a string with invalid characters shows a validation message.
- Read all four representations at once. The output panel shows binary, octal, decimal, and hexadecimal side by side and updates on every keystroke.
- Copy any single representation with the Copy button next to each row, or copy them all using the Copy All action.
- Switch bases mid-session without losing your work; picking a new input base re-interprets the typed value if it is valid, or prompts you to clear it if not.
How the Conversion Actually Works
Conversion between bases goes through an integer intermediate. JavaScript's parseInt(string, radix) parses the input into a native number; (number).toString(radix) emits it into each target base. The radix parameter is the key: it tells the parser and formatter how many distinct digits to use (2, 8, 10, or 16 here). Hexadecimal uses case-insensitive A-F for 10-15; binary uses 0 and 1 only; octal uses 0-7. The conversion is mathematically exact for any integer up to Number.MAX_SAFE_INTEGER, which is 253-1, or 9,007,199,254,740,991 in decimal.
All four output rows are computed at once rather than piped from the current output, so if you change the input base the already-parsed integer regenerates all four strings from the same source. This avoids the subtle bug where repeated conversions accumulate rounding error, which matters at boundaries near the safe-integer limit. Everything runs client-side; there is no server involved, no analytics event carries the number, and the state is discarded on tab close.
Where Base Conversion Comes Up
- Reading or writing hexadecimal colour codes (#FF8800 is R=255, G=136, B=0) when you know the decimal RGB you want.
- Decoding file permission bits (chmod 755 = 111 101 101 in binary, three bits per octal digit).
- Debugging a protocol capture where packet fields are shown in hex and you want the decimal value.
- Understanding an embedded systems datasheet that expresses register defaults in binary and actual values in hex.
- Translating between IPv4 numeric ranges (decimal dotted quad) and their hex representations for CIDR math.
- Learning or teaching the positional notation that underlies every number system humans use.
Validation and Edge Cases
- Invalid digits for the current base are blocked at the input. Typing "9" when octal is selected does nothing; typing "G" when hexadecimal is selected shows an error.
- Leading zeros are preserved in binary display for readability but have no mathematical meaning; 0b00001010 and 0b1010 are both 10.
- Case-insensitive hex input. "FF", "ff", and "Ff" all parse to 255. Output is always uppercase because it is the more common convention in programming.
- Maximum safe integer is 253-1 (9,007,199,254,740,991) because JavaScript's
numberis a double. Larger values lose precision silently; the tool flags inputs beyond this bound. - Negative numbers are displayed with a leading minus in each base; two's complement encoding is not applied because it depends on the bit width you are targeting.
- Fractional parts are not supported in this build. Converting 0.1 between bases is a famously surprising operation (0.1 decimal is an infinite repeating binary fraction 0.0001100110011...), which the tool sidesteps by accepting integers only.
A Primer on Positional Notation
Positional notation represents a number as a sum of digit-times-power-of-base terms. The decimal 437 is 4 * 102 + 3 * 101 + 7 * 100. The binary 1011 is 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20 = 11. The idea is Sumerian (base 60, around 3000 BCE) and Indian (base 10 with zero, codified by Brahmagupta in 628 CE); binary was studied by Gottfried Wilhelm Leibniz in 1703 in his Explication de l'Arithmétique Binaire, which he saw as mystically significant. Hexadecimal became a programming standard with the IBM System/360 in 1964 because 4 bits cover one hex digit and 8 bits (one byte) cover exactly two. ISO 80000-2 defines the standard notation: subscripts for bases (2510, 110012) and prefixes (0b, 0o, 0x) for the programming conventions.
When to Use a Language or CLI Tool Instead
For one-off conversions in a terminal, printf "%x\\n" 255 (bash), (255).toString(16) (Node), hex(255) (Python), or bc -q <<< "obase=16; 255" all do the job with zero UI overhead. IDE plugins for hex-decimal conversion are common; macOS Calculator has a Programmer mode, Windows Calc has a Programmer mode with bitwise operations alongside base conversion. For arbitrary-precision base conversion (hundreds of digits), Python and GMP handle it natively while JavaScript's number caps out at 253-1; BigInt plus .toString(radix) is the right path in JS. The browser tool wins when you need to see all four bases at once - spotting that a value is a round number in hex but not decimal, for example - and you do not want to open a REPL.
Frequently Asked Questions
Why are binary, octal, decimal, and hexadecimal the four default bases?
These four cover essentially every practical need in computing and everyday math. Binary is the native representation in digital circuits. Octal maps to 3-bit groups and survives for Unix file permissions. Decimal is the human default. Hexadecimal maps to 4-bit groups, so two hex digits make one byte, which is why it became the standard display format for bytes, colours, and memory addresses.
How does the tool avoid precision loss?
All intermediate arithmetic uses JavaScript's <code>number</code> type, which is an IEEE 754 double with 53 bits of integer precision. For any integer up to <code>Number.MAX_SAFE_INTEGER</code> (2<sup>53</sup>-1), <code>parseInt</code> and <code>toString</code> are exact in every base. The tool detects inputs that exceed this bound and flags them rather than silently rounding. For arbitrary-precision conversion you want BigInt or a dedicated library.
Is my input sent to a server?
No. The number-base converter is a Preact island that runs its parsing and formatting entirely in the browser. There is no fetch call per keystroke, no analytics event carrying your number, and no persistent storage. The Copy buttons use the local Clipboard API, which does not touch the network.
Why is hex such a compact representation of binary?
Because 2<sup>4</sup> = 16. Each hexadecimal digit represents exactly four binary bits, so a 32-bit integer takes 32 binary digits but only 8 hex digits. This one-to-one correspondence between hex digits and nibbles makes hex the standard display format for memory contents, byte dumps, and low-level protocol work. Octal has the same property with three bits per digit but fits less cleanly into modern 8-, 16-, 32-, and 64-bit word sizes.
Do I need to prefix hex with 0x?
Not in this tool - the input base selector tells the parser the radix directly, so typing "FF" with Hex selected is enough. Prefixes like 0x (hex), 0b (binary), and 0o (octal) are programming conventions from C, ECMAScript, and Python that let the parser infer the base from the string. <code>parseInt</code> in JavaScript handles 0x prefixes automatically when called with radix 16 or 0.
How are negative numbers handled?
The tool shows a leading minus sign in each base (for example decimal -10 becomes binary -1010). It does not apply two's complement encoding because that requires a fixed bit width (8, 16, 32, or 64 bits) which is not part of the UI. If you need two's complement representation, pick a width, add 2<sup>n</sup> to the negative value to get its unsigned representation, and convert that.
Can I convert fractional numbers like 0.1 to binary?
Not in this build. Integer-only conversion sidesteps a classic surprise: 0.1 in decimal is an infinite repeating fraction in binary (0.0001100110011001100...), which is exactly why IEEE 754 floating point cannot represent 0.1 exactly. If you need fractional conversion for a specific number of digits, compute it by hand: multiply by the target base repeatedly, taking the integer part as the next digit, and stop when the fractional part reaches zero or the desired precision.
Why does the tool support base 8 when almost nobody uses it?
Octal persists in two niches: Unix file permissions (chmod 755, chmod 644), where each octal digit encodes three permission bits, and legacy systems (PDP-11, early IBM mainframes). Including it costs nothing because the same <code>parseInt</code> / <code>toString</code> path handles radix 8 as easily as any other base. If you never touch Unix file permissions you can ignore it; if you do, having it alongside hex is a quick reference.
Is there a limit on input length?
Effectively yes, at <code>Number.MAX_SAFE_INTEGER</code>. In decimal this is 16 digits; in binary it is 53 digits; in hex it is about 13 digits. Input beyond this bound starts losing integer precision in JavaScript's <code>number</code> type. The tool shows a warning for over-large input. For truly long base conversions (cryptographic keys, hashes) use a BigInt-based library or a language with native bignum support.
What is the difference between base-10 and decimal?
They are the same thing. "Decimal" is the Latinate name for the positional notation with ten digits (0-9); "base-10" is the mathematical description. The word sometimes also means "with fractional parts" (decimal point) in casual usage - here it strictly means the radix-10 numeral system.
More Math & Calculators
Age Calculator
Calculate exact age in years, months and days from a birthdate.
Open toolArea & Volume Calculator
Calculate area of 2D shapes and volume of 3D solids.
Open toolBMI Calculator
Calculate your Body Mass Index and find your weight category.
Open toolByte / Bit Converter
Convert between bits, bytes, KB, MB, GB, TB and PB.
Open toolDiscount Calculator
Calculate discount amount, sale price, savings, and discounted value with optional sales tax. Supports stacked coupons.
Open toolFibonacci Sequence Generator
Generate Fibonacci numbers up to any length.
Open tool