Binary Converter — Binary, Decimal, Octal & Hex
Convert non-negative integers among binary, octal, decimal and hexadecimal exactly, including values larger than JavaScript's safe integer range.
Binary Converter
Background.
Binary, decimal, octal and hexadecimal are not four different values. They are four alphabets for writing the same non-negative integer. Decimal uses ten digit symbols and each place is ten times the place to its right. Binary uses only 0 and 1 and each place is twice the next. Octal uses eight symbols, while hexadecimal uses sixteen: 0 through 9 followed by A through F for values ten through fifteen.
This converter keeps that distinction visible. Enter an integer in any of the four notations and it prints all four representations at once. It does not pass the value through JavaScript's ordinary number type, so a long identifier is not silently rounded at 9,007,199,254,740,991. The arithmetic is performed digit by digit with a high-precision Decimal.js context and the full decimal answer stays text all the way to the result.
Binary and hexadecimal fit together especially neatly. NIST explains that four binary digits correspond to one hexadecimal digit, and RFC 4648 publishes the complete mapping. Binary 1010 is hexadecimal A, 1111 is F, and an eight-bit byte can therefore be displayed as exactly two hexadecimal digits when padding matters. Octal groups binary digits by threes instead. Those grouping shortcuts are a way to check the result, but the calculator itself evaluates the integer positionally and therefore handles an input whose digit count is not a tidy multiple of three or four.
Prefixes are accepted for convenience: 0b for binary, 0o for octal, 0d for decimal and 0x for hexadecimal. Underscores and leading zeroes may be used for readability and are removed before conversion. The result omits prefixes and insignificant leading zeroes so the four lines are easy to copy. Zero remains 0 rather than becoming an empty string.
The width figures describe the shortest representation, not a storage allocation. Decimal 255 needs eight significant binary digits and two hexadecimal digits, but a file format could place that value in a sixteen-bit or thirty-two-bit field by adding leading zeroes. The extra positions do not change the integer. Likewise, a hexadecimal digit is a convenient display for four bits, but a value containing an odd count of hex digits is not malformed. Its leftmost group simply uses fewer than four significant bits. Keeping numeric value separate from field width prevents a common conversion error: treating display padding as new information.
The input limit is also about exactness rather than machine architecture. You may enter values much larger than a 64-bit processor register, and the converter will preserve every digit. It uses a local precision context large enough for the published 128-character envelope, then constructs each result by exact integer division. There is no logarithm used to guess the answer's length and no floating-point shortcut used to parse the source string. That is why the full 2^128 − 1 value and similarly large decimal identifiers round-trip without losing their final digits.
Scope matters with bit strings. The digits 11111111 can mean the unsigned integer 255, the signed eight-bit integer −1, a byte in a text encoding, or part of a floating-point value. Nothing in the digits alone chooses among those meanings. This page treats every input as a non-negative mathematical integer. It deliberately does not guess a word width, two's-complement sign, character encoding or byte order. Use it when you want the value of an integer in another base; use a domain-specific decoder when the surrounding bits carry structure.
What is binary converter?
A positional numeral system assigns a base to a string of digits. Reading from the right, the places have weights base to the powers 0, 1, 2 and onward. Binary 1101 therefore means 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 13. Decimal 13 expresses the same value as 1×10 + 3, octal 15 expresses it as 1×8 + 5, and hexadecimal D expresses it with the single digit whose value is thirteen. Conversion can be done without a floating-point approximation: consume the source digits from left to right, multiplying the accumulated integer by the source base and adding the next digit. To write the result in another base, repeatedly divide by that base and read the remainders in reverse order. Because hexadecimal has sixteen symbols and sixteen equals 2⁴, every hexadecimal digit maps to four binary positions. Because eight equals 2³, every octal digit maps to three. Padding is contextual rather than numeric: hexadecimal 1, 01 and 0001 are the same integer even though a protocol may require a fixed-width field.
How to use this calculator.
- Choose the notation already used by your input. Do not choose the notation you want as the output; all four outputs are always shown.
- Enter a non-negative integer. Conventional 0b, 0o, 0d or 0x prefixes are optional when they agree with the selected mode.
- Use underscores if they make a long value easier to read. They are separators only and do not affect the value.
- Read the exact string beside the target base. The converter removes insignificant leading zeroes and uses uppercase A–F.
- If the bit string is supposed to be signed, a character, a packet field or a floating-point encoding, establish its width and encoding before interpreting it; this page intentionally treats it only as an unsigned integer.
The formula.
The positional rule can be written as a sum, but the left-to-right recurrence is safer to implement. Start at zero. For every source digit, multiply the accumulated value by the source base and add the digit. Binary 11010110 becomes 1, then 3, 6, 13, 26, 53, 107 and finally 214. Every operation is integer arithmetic.
To produce a target representation, divide the value by the target base. The remainder is the rightmost digit; divide the quotient again and continue until it reaches zero. For 214 in hexadecimal, 214 modulo 16 is 6 and the quotient is 13. Thirteen maps to D, so reversing the remainders gives D6. In octal, the remainders are 6, 2 and 3, giving 326. Zero is handled explicitly because repeated division would otherwise produce no digits.
Hex grouping is an independent cross-check. RFC 4648's base-16 alphabet assigns A through F to ten through fifteen, and each character represents four bits. Pad 11010110 on the left to groups of four: 1101 is D and 0110 is 6. Octal groups from the right in threes: 011, 010, 110 becomes 3, 2, 6. Padding added only to form groups is discarded in the canonical result.
The accepted input length is capped at 128 characters and evaluated with 220 decimal digits of working precision. This makes every accepted value exact, including a 128-digit hexadecimal integer, while preventing accidental submission of an enormous string that would add no practical value. The decimal output remains a string; converting it to a JavaScript Number would destroy exactness for many perfectly valid inputs.
A worked example.
Convert binary 11010110. Positional evaluation gives 1×128 + 1×64 + 0×32 + 1×16 + 0×8 + 1×4 + 1×2 + 0 = 214. For hexadecimal, split the binary digits into groups of four from the right: 1101 and 0110. RFC 4648's alphabet maps 1101 to digit D and 0110 to digit 6, so the hexadecimal representation is D6. For octal, pad on the left and group by threes: 011 010 110 maps to 3, 2 and 6, so the result is 326. The exact outputs are binary 11010110, octal 326, decimal 214 and hexadecimal D6. The unpadded value uses eight binary digits and two hexadecimal digits.
Frequently asked questions.
How do I convert binary to decimal?
How do I convert binary to hexadecimal?
Why does hexadecimal use letters?
Are 0xFF and FF the same value?
Do leading zeroes change a binary number?
Can I convert a negative binary number here?
Why is my long decimal value returned as text?
Does this convert text or files to binary?
References& sources.
- [1]NIST IR 8354 (2022), §2.2, explains binary and hexadecimal positional representations, the four-bits-per-hex-digit relationship, and the example 0x61 = binary 01100001 = decimal 97.
- [2]RFC 4648, §8, specifies the base-16 alphabet 0–9 and A–F and maps each hexadecimal character to four bits.
- [3]RFC 7373, §4, defines textual unsigned integers using decimal digits or the 0x and 0b base markers.
- [4]NIST SP 800-38F, §4.5, independently defines the 0x hexadecimal marker and gives a hexadecimal-to-binary worked example.
- [5]NIST Digital Library of Mathematical Functions §3.1 identifies base 2 as the binary system and base 16 as hexadecimal in its computer-arithmetic conventions.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 977 calculators remain free
- No billing is enabled