Audited 31 Jul 2026·Last updated 28 Oct 2026·5 citations·Tier 1·0 uses

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

Input notation
Up to 128 digits. Underscores and leading zeroes are accepted. Fractions, signs and signed machine-word interpretations are outside this calculator.
Binary (base 2)
11010110
The value in base 2, using only 0 and 1, with no prefix and no leading zeroes.
Octal (base 8)
326
Decimal (base 10)
214
Hexadecimal (base 16)
D6
Significant binary digits
8
Significant hexadecimal digits
2

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.

  1. 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.
  2. 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.
  3. 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.
  4. Keep to 128 digits or fewer after any prefix and underscores are removed; leading zeroes count toward that limit.
  5. 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.

value = (((d₀ × b + d₁) × b + d₂) …); output digits = repeated value mod t

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.

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.

value11010110
input Basebinary

Frequently asked questions.

How do I convert binary to decimal by hand?
Write the place values over the bits from the right, 1, 2, 4, 8, 16 and so on, then add the values that sit over a 1. Binary 10110 has ones under 16, 4 and 2, so it is 22. For long strings the doubling method is quicker: run through the bits from the left, doubling the total and adding each bit.
How do I convert decimal to binary by hand?
Divide by 2 repeatedly and write down each remainder. For 214: 107 remainder 0, 53 remainder 1, 26 remainder 1, 13 remainder 0, 6 remainder 1, 3 remainder 0, 1 remainder 1, 0 remainder 1. Reading the remainders from last to first gives 11010110. The same method with 8 or 16 as the divisor gives octal or hexadecimal.
Why does one hexadecimal digit stand for exactly four bits?
Four bits have 2⁴ = 16 possible patterns, from 0000 to 1111, and hexadecimal has exactly sixteen digits, so each pattern gets one character. That makes translation mechanical: 10101111 splits into 1010 and 1111, which are A and F, so it is AF, or 175 in decimal. A byte is always two hex digits once padded, which is why a 256-bit SHA-256 hash prints as 64 hexadecimal characters, comfortably inside the 128-digit limit here.
Why are Unix file permissions written in octal?
Each class of user (owner, group, others) has three permission bits, read, write and execute, and three bits make one octal digit. In chmod 755, 7 is 111 (read, write, execute) and each 5 is 101 (read and execute), so the bits are 111101101, or rwxr-xr-x. As a decimal number that is 493, which nobody would recognise.
How do I convert a hex colour code like #FF8800?
Drop the #, which the converter rejects, and treat each pair of digits as one colour channel: FF is 255 red, 88 is 136 green and 00 is 0 blue. Convert the pairs one at a time to get those channel values. Entered as a single number, FF8800 is 16,746,496, which is correct but rarely what a designer wants. A three-digit code such as #F80 is shorthand in which each digit is doubled, so it means FF8800 too.
How many bits do I need to store a number?
The bit length output tells you: it is the length of the binary answer. Eight bits hold 0 to 255, so 255 needs 8 bits but 256 needs 9. In general n bits reach 2ⁿ − 1, so 32 bits reach 4,294,967,295 and 64 bits reach 18,446,744,073,709,551,615. Divide the bit length by 8 and round up to get the bytes required: a value with a bit length of 9 already needs two bytes.
I typed 0b101 in hexadecimal mode and got 45,313. Why?
Prefixes are only recognised when they match the chosen notation. In hexadecimal mode, 0, b, 1, 0, 1 are all valid hex digits, so 0b101 is read as hex B101, which is 45,313 in decimal. Switch the notation to binary and the same text gives 5. The 0d prefix behaves the same way in hexadecimal mode.
Why does 11111111 mean −1 in some programs?
Because those programs read it as a signed number in two's complement, where an 8-bit pattern with a leading 1 stands for its unsigned value minus 256. Unsigned, 11111111 is 255; signed, it is 255 − 256 = −1. The answer depends on the field width, which the digits do not carry: padded to 16 bits as 0000000011111111, the same eight ones are plain +255 even when read as signed. This converter always gives the unsigned value.
Can I convert fractions such as 0.1 to binary?
Not here; the converter accepts whole numbers only, and a decimal point is rejected. Fractions are also awkward in principle: decimal 0.1 has no finite binary form and repeats forever as 0.000110011001100…, which is why computers store it only approximately. For a fractional value you need to decide how many bits to keep, which is a separate calculation.
Why does a very long number keep its last digits here when other tools change them?
JavaScript's standard numbers hold integers exactly only up to 9,007,199,254,740,991, so 9,007,199,254,740,993 typed into many tools becomes 9,007,199,254,740,992. This converter keeps the value as an exact integer, giving 20000000000001 in hex. Even the 128-bit maximum, 340,282,366,920,938,463,463,374,607,431,768,211,455, survives unchanged.

How this page was produced

Published by
Quanta Calculator
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
Coming soon