Number Base Converter

Converts a number between binary, octal, decimal and hexadecimal, showing all four representations at once plus the bit length of the value. Digits are parsed against the chosen base using positional notation, where each digit is multiplied by the base raised to its position, and the result is re-expressed by repeated division in each target base. Arbitrary-precision integer arithmetic keeps conversions exact for values of any length, including negatives.

Conversions
Bits needed

Type a number, pick the base it is written in, and the table shows the same value in binary, octal, decimal and hexadecimal at once. Binary output is grouped into four-digit nibbles, decimal gets thousands separators, and hexadecimal is printed in uppercase, so each row is ready to paste wherever it is headed. Below the table, the bits-needed figure reports how many binary digits the absolute value occupies, which tells you at a glance whether it fits in a byte, a 16-bit register or a 64-bit integer. Conversions run in exact arbitrary-precision arithmetic, so a value of any length converts without rounding, and spaces in the input are ignored.

How positional conversion works

All four bases work the same way; only the multiplier changes. A positional numeral is a list of digits, and each digit is worth its face value times a power of the base determined by its position, counted from zero at the right-hand end:

n = dk × bk + … + d1 × b1 + d0 × b0

Reading a numeral in, the calculator applies exactly that rule, starting from the leftmost digit and folding the rest in one at a time: multiply the running total by the base, add the next digit, repeat. Writing the value out in a new base is the same process run backwards, known as repeated division. Divide the value by the target base and keep the remainder as the lowest digit, then divide the quotient for the next digit, stopping when the quotient reaches zero; the remainders, read in reverse order of discovery, are the digits of the answer. The value itself never changes during any of this. Two hundred and fifty-five sheep are the same flock whether the tally reads 255, FF or 1111 1111, because a base is a notation, not a quantity.

Converting 255 to binary by hand

The default input makes a compact worked example. Divide 255 by 2 repeatedly and note each remainder: 255 ÷ 2 is 127 remainder 1, then 127 ÷ 2 is 63 remainder 1, 63 ÷ 2 is 31 remainder 1, 31 ÷ 2 is 15 remainder 1, 15 ÷ 2 is 7 remainder 1, 7 ÷ 2 is 3 remainder 1, 3 ÷ 2 is 1 remainder 1, and finally 1 ÷ 2 is 0 remainder 1. Eight divisions, eight remainders, every one of them 1, so 255 in binary is 11111111. That is no coincidence: 255 is 28 − 1, the largest value eight bits can hold. The same routine with 8 as the divisor takes three steps, since 255 ÷ 8 is 31 remainder 7, 31 ÷ 8 is 3 remainder 7, and 3 ÷ 8 is 0 remainder 3, giving the octal form 377. With 16 it takes two: 255 ÷ 16 is 15 remainder 15, and 15 ÷ 16 is 0 remainder 15; the digit for fifteen is F, so the hexadecimal form is FF. Checking against the positional formula runs the other way, and both books balance: 3 × 64 + 7 × 8 + 7 = 255, and 15 × 16 + 15 = 255. The bits-needed figure is 8, the length of 11111111.

Base 60 in Babylon, base 2 in 1703

Positional notation is far older than computing. Base-60 counting originated with the Sumerians, around 2000 BC, and the Babylonians who inherited it made the decisive advance of using it positionally, keeping accounts and astronomical tables in place-value base 60. Why 60 was chosen is not recorded, though the base is conspicuously handy for fractions, being divisible by every number from 1 to 6. The momentum of that choice still divides an hour into 60 minutes, a minute into 60 seconds and a circle into 360 degrees, some four thousand years on: an angle read out as degrees, minutes and seconds is a base-60 numeral being spelled aloud, long after anyone last wrote everyday numbers that way.

Binary, by contrast, entered the record at a known point. Gottfried Wilhelm Leibniz set out binary arithmetic in the Explication de l'arithmétique binaire, published in the Paris Academy's Mémoires for 1703, showing how to write any number with only the characters 0 and 1 and how to add, subtract, multiply and divide in that notation. The paper's full title promises something stranger: remarks on the sense it gives to the ancient Chinese figures of Fohy. Leibniz had sent his way of counting by 0 and 1 to Joachim Bouvet, a French Jesuit missionary in Peking, and Bouvet recognised it as the key to the hexagrams of the I Ching, the divination figures built from six broken or unbroken lines. Read a broken line as 0 and an unbroken one as 1 and each hexagram is a six-bit binary numeral, all 64 possibilities present, 64 being exactly 26. The hexagrams did not inspire binary, since the correspondence was noticed only after Leibniz sent his arithmetic east, but he took it seriously enough to put it in his title, and the paper fixed binary notation in the mathematical record two and a half centuries before there was a machine to run it on.

Octal on the PDP-8, hexadecimal on the System/360

Octal came first in computing because early word sizes cooperated with it. Three bits make one octal digit, so any machine whose word length is a multiple of three prints its words as a whole number of octal digits with nothing left over. Digital Equipment Corporation's PDP-8, introduced on 22 March 1965 at $18,500 as the first minicomputer to sell for under $20,000, had a 12-bit word, which reads as exactly four octal digits; more than 50,000 of the original model were sold, and its programmers wrote addresses and instruction words in octal as a matter of course.

Hexadecimal displaced it when the byte changed shape. IBM's System/360, announced on 7 April 1964 as a single compatible family of computers, standardised the 8-bit byte where characters had commonly been six bits, and eight is not a multiple of three: an octal rendering straddles byte boundaries as soon as bytes sit side by side in a longer word. Sixteen, though, is 24, so one hexadecimal digit corresponds to exactly four bits and a byte is always exactly two hex digits, whatever surrounds it. In their April 1964 paper on the System/360's architecture, Amdahl, Blaauw and Brooks record that "base 16 was selected for floating point", and as the 8-bit byte became the industry's universal unit, hex went along with it as the natural notation for bytes. That one-digit-to-four-bits mapping is also why this calculator groups binary output into nibbles: each four-digit group in the binary row is one digit of the hexadecimal row, so the two can be checked against each other by eye, with no arithmetic at all.

Reading the bits-needed figure

The bit length answers a practical question: what is the smallest register this number fits in as an unsigned quantity? Anything with 8 bits or fewer fits in a byte, since a byte spans 0 through 255. Sixteen bits reach 65,535, thirty-two reach 4,294,967,295, and sixty-four reach 18,446,744,073,709,551,615. Zero is reported as needing 1 bit, the usual convention, since storing it still takes a digit.

Negative numbers deserve a caveat. The calculator shows a negative value the way mathematics writes it, as a magnitude with a minus sign, in every base. Hardware does not: machines store negatives in two's complement, where the stored pattern depends on the register width, so minus one occupies an 8-bit register as 1111 1111 and a 16-bit register as sixteen ones. Because no fixed width is assumed here, there is no single two's-complement form to print, and the signed-magnitude form is shown instead. To decode a two's-complement pattern, convert the pattern itself as an unsigned value and handle the sign separately.

Assumptions and conventions

Input is an integer in the selected base: digits only, an optional leading minus sign, and spaces anywhere, which are stripped so grouped values paste cleanly. Prefixes such as 0x or 0b are not recognised and are reported as invalid characters, as is any digit that does not belong to the chosen base; typing 2 while binary is selected, or G while hexadecimal is, names the offending character rather than failing silently. Hexadecimal input is case-insensitive and hexadecimal output is uppercase. Fractions and exponents are out of scope, since the converter handles whole numbers only. Arithmetic runs on arbitrary-precision integers rather than ordinary JavaScript numbers, which are floating-point doubles exact only up to 9,007,199,254,740,991, or 253 − 1; past that point a float-based converter silently rounds while this one stays exact, up to a ceiling of 1,000 digits on the input to keep the page responsive. The comma separators in the decimal row and the four-digit grouping in the binary row are purely cosmetic, so strip them before feeding a value to code that does not expect separators.

Frequently asked questions

How do you convert a decimal number to binary by hand?

Divide the number by 2, write down the remainder, then divide the quotient by 2 again, repeating until the quotient reaches zero. The remainders, read in reverse order, are the binary digits. For 255 all eight divisions leave remainder 1, so the answer is 11111111. The same method works for any target base, dividing by 8 for octal or by 16 for hexadecimal.

Why do programmers use hexadecimal instead of binary?

Because 16 is 2 to the 4th power, one hexadecimal digit stands for exactly four bits, so a byte is always two hex digits and converting between hex and binary needs no arithmetic, just digit-for-digit substitution. Binary strings also get long fast: a 32-bit value takes 32 characters in binary but only 8 in hex, without losing the bit-level detail that decimal hides.

What is 255 in binary, octal and hexadecimal?

255 is 11111111 in binary, 377 in octal and FF in hexadecimal. It equals 2 to the 8th power minus 1, the largest value an unsigned 8-bit byte can hold, which is why it appears all over computing, from the 0 to 255 range of each channel in an RGB colour to the four numbers of an IPv4 address.

Why are there 60 minutes in an hour and 360 degrees in a circle?

Both descend from the base-60 numeral system that the Babylonians inherited from the Sumerians and used positionally for accounting and astronomy, and the convention has simply never been displaced. Reading an angle or a coordinate as degrees, minutes and seconds is spelling out a base-60 numeral to this day, thousands of years after anyone last wrote ordinary numbers that way.

Who invented the binary number system?

Gottfried Wilhelm Leibniz gave binary arithmetic its founding published account in the Paris Academy's Mémoires for 1703, in a paper showing how to write and calculate with only the characters 0 and 1. The paper also reports that when Leibniz sent his way of counting to Joachim Bouvet, a Jesuit missionary in Peking, Bouvet recognised it as the key to the 64 hexagrams of the I Ching, whose broken and unbroken lines read as six-digit binary numerals. The hexagrams did not inspire binary; the connection surfaced only after the fact.

How many bits do I need to store a number?

The bit length of a whole number is the count of digits in its binary form, which this calculator reports as bits needed. A value fits unsigned in 8 bits up to 255, in 16 bits up to 65,535, in 32 bits up to 4,294,967,295 and in 64 bits up to 18,446,744,073,709,551,615. Signed types spend one bit on the sign, roughly halving the reach, and zero counts as needing 1 bit by convention.