Binary Converter — Binary, Decimal, Octal & Hex
Convert a whole number between binary, octal, decimal and hex in one step, exactly, up to 128 digits, with the bit length and hex digit count it needs.
Binary Converter
Background.
11010110, 326, 214 and D6 are the same number. Only the alphabet changes: binary writes it with two symbols, octal with eight, decimal with ten and hexadecimal with sixteen. Converting between them never alters the quantity, only how it is spelled, and that is all this converter does. Type an integer in one base and it is written out in all four.
The bases turn up in different corners of computing. Binary is what the hardware stores, and it is how you read a subnet mask or a set of flag bits. Hexadecimal is binary in shorthand, one character for every four bits, so it fills colour codes, memory addresses, MAC addresses and cryptographic hashes. Octal packs three bits per digit, which is why Unix file permissions such as 755 are written in it. Decimal is the one people count in.
Long values are where most quick tools go wrong. Many web calculators parse input into JavaScript's ordinary number type, which stores integers exactly only up to 9,007,199,254,740,991. Type 9,007,199,254,740,993 into one of those and you may get back a number ending in 2. Here the digits are processed as an exact integer from start to finish, so a 128-digit hexadecimal value, a 39-digit decimal identifier or the full 128-bit maximum all come back with every digit intact.
The converter treats every input as a non-negative whole number. A string of bits can also stand for a negative number in two's complement, a letter, part of a floating-point value or a pixel, but the bits alone cannot say which; that depends on a width and an encoding decided elsewhere. For anything other than a plain unsigned integer, use a decoder built for that format, then come back here for the arithmetic.
What is binary converter?
A positional numeral system gives each place a weight that is a power of the base. Reading from the right, the places in binary are worth 1, 2, 4, 8, 16 and so on; in octal 1, 8, 64, 512; in decimal 1, 10, 100; in hexadecimal 1, 16, 256, 4,096. Binary 1101 is therefore 8 + 4 + 0 + 1 = 13, the same value decimal writes as 13, octal as 15 and hexadecimal as the single digit D. Hexadecimal needs sixteen symbols, so after 0 to 9 it uses A to F for ten to fifteen; RFC 4648 standardises that alphabet and treats upper and lower case alike. Because 16 = 2⁴ and 8 = 2³, every hexadecimal digit corresponds to exactly four binary digits and every octal digit to three, which is what makes those two bases convenient shorthand for binary. Binary itself is the native base of computers because a circuit can tell two states apart, on or off, high voltage or low, far more reliably than it could tell ten; every other base on a screen is a more readable view of those two-state digits.
How to use this calculator.
- Set Input notation to the base your digits are already written in, not the one you want; all four bases are shown in the results either way.
- Type the digits. A prefix is optional but must match the notation you chose: 0b for binary, 0o for octal, 0d for decimal, 0x for hexadecimal. Lower-case a–f is fine.
- Use underscores to break up a long value, such as 1101_0110. Spaces, a # in front of a colour code, a minus sign and a decimal point are all rejected.
- Keep to 128 digits or fewer after any prefix and underscores are removed; leading zeroes count toward that limit.
- Read the four results. Leading zeroes are dropped, so pad them back yourself if a format needs a fixed width, such as eight binary digits for a byte.
The formula.
Reading a number in its source base uses the left-to-right rule written as value = (((d₀ × b + d₁) × b + d₂) …): start at zero, and for each digit multiply the running total by the base b and add the digit's value. This is Horner's method for evaluating a polynomial, and it avoids computing a separate power of the base for every position. Writing that value in a target base t runs the other way. Divide by t; the remainder is the last digit. Divide the quotient by t again for the next digit to the left, and so on until the quotient reaches zero, then read the remainders in reverse. Zero is the one case that needs a rule of its own, since dividing it produces no remainders at all; it is written as 0 in every base. Every step is whole-number arithmetic, so nothing is rounded. The arithmetic carries enough digits to hold the largest accepted input exactly: 128 hexadecimal F's is a 155-digit decimal number. The grouping shortcuts are a convenient way to check results by eye. For binary to hexadecimal, split the bits into fours from the right and translate each group; for octal, split into threes. Octal and hexadecimal do not share a grouping, so the reliable way between them is through binary or decimal. The two count outputs come straight from the results: the bit length is the number of characters in the binary answer, which is the fewest bits that can store the value, and the hexadecimal count is the number of characters in the hex answer. Apart from zero, a value with bit length n lies between 2ⁿ⁻¹ and 2ⁿ − 1, so 214, with 8 bits, falls between 128 and 255.
A worked example.
Take the binary input 11010110. Working left to right and doubling as you go: start with 1; double and add 1 to get 3; double and add 0 to get 6; then 13, 26, 53, 107 and finally 214. The place-value method agrees: 128 + 64 + 16 + 4 + 2 = 214. For hexadecimal, split the bits into fours from the right: 1101 and 0110. 1101 is thirteen, written D, and 0110 is six, so the result is D6. For octal, pad the front with one zero and split into threes: 011, 010, 110, which are 3, 2 and 6, giving 326. Checking that the other way, 3 × 64 + 2 × 8 + 6 = 192 + 16 + 6 = 214. The converter reports binary 11010110, octal 326, decimal 214 and hexadecimal D6, with a bit length of 8 and 2 hexadecimal digits. The value fills a byte exactly, and its leading 1 sits in the 128s place. That leading 1 is why a program reading the same byte as a signed 8-bit number would show −42 rather than 214. The same reading of bits helps with a network mask. Enter the decimal value 4294967040 and the converter returns hexadecimal FFFFFF00 and a 32-bit binary string of twenty-four 1s followed by eight 0s. Those twenty-four leading ones are the /24 in a CIDR address, and each group of eight bits, 11111111, 11111111, 11111111 and 00000000, is one of the four numbers in the familiar dotted form 255.255.255.0.
Frequently asked questions.
How do I convert binary to decimal by hand?
How do I convert decimal to binary by hand?
Why does one hexadecimal digit stand for exactly four bits?
Why are Unix file permissions written in octal?
How do I convert a hex colour code like #FF8800?
How many bits do I need to store a number?
I typed 0b101 in hexadecimal mode and got 45,313. Why?
Why does 11111111 mean −1 in some programs?
Can I convert fractions such as 0.1 to binary?
Why does a very long number keep its last digits here when other tools change them?
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.
How this page was produced
- Published by
- Quanta Calculator
- Overseen by
- Daniel, Quanta Calculator Researcher
- Primary sources
- 5 cited below
- Method
- value = (((d₀ × b + d₁) × b + d₂) …); output digits = repeated value mod t
- Published
- Last verified
Built with AI assistance and verified by automated tests against the cited sources — every worked example on this page is computed by the same code that runs the calculator. How we build and check calculators.
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 1560 calculators remain free
- No billing is enabled