Number Base Converter Guide: Binary, Octal, Decimal and Hexadecimal

Why more than one base

Decimal, base ten, is the system of everyday life, inherited from counting on ten fingers. Binary, base two, is the system of digital electronics, because a switch, a transistor or a memory cell most naturally has two states, on and off, one and zero. Octal, base eight, and hexadecimal, base sixteen, are shorthand for binary: they group binary digits into chunks that are easier for humans to read and write, three bits per octal digit and four bits per hexadecimal digit. A Number Base Converter translates between these systems, and understanding the translation is essential for anyone who reads memory addresses, colour codes, file permissions or network addresses.

Every positional number system works the same way: the value of a digit depends on its position, and each position is worth the base raised to a power. In decimal, the number two hundred and fifty-five means two hundreds, five tens and five ones, because the positions from the right are worth one, ten and one hundred. In binary, the positions from the right are worth one, two, four, eight, sixteen, and so on, doubling each time. The system changes, but the principle does not, and that principle is the whole of base conversion.

Hexadecimal needs six extra symbols beyond the ten decimal digits, and it borrows the letters A to F, where A means ten, B eleven, C twelve, D thirteen, E fourteen and F fifteen. A single hexadecimal digit therefore represents any value from zero to fifteen, which is exactly the range of four binary digits, from 0000 to 1111. That neat correspondence is why hexadecimal, rather than any other base, became the standard shorthand for binary in computing.

Place value in each base

In binary, each position doubles. The binary number 11111111 has eight ones, in positions worth one, two, four, eight, sixteen, thirty-two, sixty-four and one hundred and twenty-eight. Adding them gives one plus two plus four plus eight plus sixteen plus thirty-two plus sixty-four plus one hundred and twenty-eight, which is two hundred and fifty-five. Eight binary digits, called a byte, can therefore represent any value from zero to two hundred and fifty-five, which is why bytes are the basic unit of storage.

In octal, each position is worth a power of eight: one, eight, sixty-four, and so on. The octal number 377 means three sixty-fours, seven eights and seven ones: three multiplied by sixty-four is one hundred and ninety-two, seven multiplied by eight is fifty-six, and adding seven gives two hundred and fifty-five. Octal was once common in computing, notably for Unix file permissions, where three octal digits describe read, write and execute rights for owner, group and others, but hexadecimal has largely replaced it elsewhere.

In hexadecimal, each position is worth a power of sixteen: one, sixteen, two hundred and fifty-six, and so on. The hexadecimal number FF means fifteen sixteens plus fifteen ones, which is two hundred and forty plus fifteen, which is two hundred and fifty-five. Colour codes use this directly: a colour written as six hexadecimal digits is three bytes, one each for red, green and blue, each ranging from 00 to FF, or zero to two hundred and fifty-five in decimal. That connection between number bases and everyday web design is one reason hexadecimal remains familiar even to people who never write programs.

A worked example through all four bases

Convert two hundred and fifty-five through all four bases. In decimal it is 255. In hexadecimal, divide by sixteen: two hundred and fifty-five divided by sixteen is fifteen remainder fifteen, so the digits are F and F, giving FF. In octal, divide by eight repeatedly: two hundred and fifty-five divided by eight is thirty-one remainder seven, thirty-one divided by eight is three remainder seven, and three divided by eight is zero remainder three, giving 377 reading the remainders backwards. In binary, the place-value addition above gives 11111111. All four strings denote the same quantity, and a converter lets you move between them without performing the repeated division by hand.

A second example confirms the method on a smaller number. Forty-two in decimal converts to binary by repeated division by two: forty-two divided by two is twenty-one remainder zero, twenty-one divided by two is ten remainder one, ten divided by two is five remainder zero, five divided by two is two remainder one, two divided by two is one remainder zero, and one divided by two is zero remainder one. Reading the remainders backwards gives 101010. Check by place value: thirty-two plus eight plus two is forty-two, which matches. In hexadecimal, forty-two divided by sixteen is two remainder ten, and ten is A, giving 2A. In octal, forty-two divided by eight is five remainder two, giving 52. Each route agrees, which is the check that matters.

Converting binary to hexadecimal directly is easier than going through decimal: group the binary digits in fours from the right and translate each group. The binary number 101010 groups as 0010 and 1010, which are two and ten, giving 2A, matching the division result. Grouping in threes gives octal by the same method. These groupings are why programmers prefer hexadecimal for reading binary data: a long binary string becomes a short hexadecimal string at a glance, with no arithmetic at all.

Where each base appears

Binary appears wherever hardware is described: processor registers, logic circuits, and the bit patterns of data itself. Hexadecimal appears in memory addresses, colour codes, cryptographic digests, media access control addresses, and the addresses of the newer internet protocol, where long binary addresses would be unusable in any other form. Octal survives in file permissions and in some older systems. Decimal remains the base for human-facing quantities: prices, counts, measurements and results presented to users, who think in tens.

Fractions add a complication worth knowing. Just as one third has no exact finite decimal representation, many simple decimal fractions have no exact finite binary representation: nought point one in decimal repeats forever in binary, which is why floating-point arithmetic in computers produces tiny rounding errors that programmers must handle. Base conversion of integers is exact; base conversion of fractions is often approximate, and the approximation is a property of the bases, not a flaw in the converter.

Negative numbers and very large numbers introduce further conventions, such as two's complement for negatives and fixed bit widths for storage, which decide how a bit pattern is interpreted. A converter that reports a value for a given bit width is applying one of those conventions, and the result should be read with the width in mind, because the same bit pattern can mean different values under different widths and conventions.

Using the converter well

The practical routine is to enter the value, confirm the input base, and read the equivalents, checking at least one conversion by place value or by grouping, especially when the result will be used in code or configuration. A single wrong digit in a hexadecimal address or colour code produces a silently wrong result, not an error message, so the check is the important step, not the conversion itself.

Related tools include the Colour Converter for hexadecimal colour codes specifically, the guide to ASCII Conversion for the character codes that underlie text, and the Scientific Calculator for the arithmetic that surrounds base conversion. Bases are a notation, not a different kind of number, and fluency in moving between them is fluency in reading the machine's own language.