Number Bases
How To Convert Number Bases
A number base is just a choice of how many digits to count to before starting a new column. Converting between bases means regrouping the same quantity into different columns, and the arithmetic is the same place-value arithmetic you already use in decimal.
Quick Answer
value = sum of (digit x base^position)
- base
- How many digits the system uses
- digit
- The symbol in each column, from 0 to base minus 1
- position
- Column index, counting from zero at the right
Decimal 255 is 11111111 in binary, 377 in octal and FF in hexadecimal. Each base groups the same quantity into columns that grow by a different factor.
What Is How To Convert Number Bases?
A number base, also called a radix, is the number of distinct digit symbols a counting system uses. Decimal uses ten, binary uses two, octal uses eight and hexadecimal uses sixteen.
In any base, the value of a number is the sum of each digit multiplied by the base raised to the power of its position, counting from zero at the rightmost column. That single rule is the whole of place-value notation.
Decimal 255 means two hundreds, five tens and five ones. The same quantity in binary is 11111111, which is eight columns of one, because each column is a power of two rather than a power of ten.
Binary is the natural base for digital hardware because a wire either carries a voltage or it does not. Eight binary digits, a byte, can represent 256 distinct values, which is why 255 is the largest value a single byte holds.
Octal groups binary digits in threes, so one octal digit stands for exactly three bits. It was common on older systems with word lengths that were multiples of three, and it survives in file permission codes on Unix systems.
Hexadecimal groups binary digits in fours, so one hex digit stands for exactly four bits. Two hex digits make a byte, which is why hex is the standard shorthand for memory addresses, colour codes and byte dumps.
Hexadecimal needs sixteen digit symbols but only ten exist as numerals, so the letters A to F stand for the values ten through fifteen. Case is irrelevant, so FF and ff mean the same thing.
Converting from another base to decimal is the easiest direction: multiply each digit by its place value and add. Converting from decimal to another base is done by repeated division, taking the remainders in reverse order.
Converting between binary, octal and hex never needs decimal at all. Because eight and sixteen are powers of two, you can regroup the bits directly: three bits per octal digit, four bits per hex digit.
The base is usually written as a subscript to remove ambiguity, because 11 means three in binary, nine in decimal and seventeen in hex. Where subscripts are unavailable, a prefix such as 0x for hex or 0b for binary is used.
Negative numbers need a convention of their own. A leading minus sign is the simple approach, while two's complement is what hardware uses to represent signed integers without a separate sign bit.
Fractional values extend the same rule to the right of the point, with negative powers of the base. Binary fractions cannot represent one tenth exactly, which is why decimal arithmetic on a computer sometimes shows small rounding artefacts.
The calculator takes a value and the base it is written in, and shows the same quantity in decimal, binary, octal and hexadecimal along with its bit length. It accepts a leading minus sign and ignores spaces and underscores used as digit separators.
Formula
value = d(n-1) x b^(n-1) + ... + d1 x b^1 + d0 x b^0
Each digit is multiplied by the base raised to its column index, counting from zero at the right.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| d_i | Digit | digit | The digit in column i, from zero to base minus one. |
| b | Base | radix | How many digits the system uses. |
| i | Position | index | Column index, zero at the rightmost digit. |
1 octal digit = 3 bits, 1 hex digit = 4 bits
Because eight and sixteen are powers of two, bits can be regrouped directly without passing through decimal.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| octal | Octal digit | bits | Three binary digits. |
| hex | Hex digit | bits | Four binary digits. |
How To Calculate How To Convert Number Bases
- 1
Write the digits in place
Line the digits up and number the columns from zero at the right, so the rightmost digit is the base to the power zero.
- 2
Multiply each digit by its place value
In binary the place values are 1, 2, 4, 8, 16 and so on. In hex they are 1, 16, 256, 4096.
- 3
Add the products for decimal
The sum is the value in decimal. For 11111111 that is 128 plus 64 plus 32 plus 16 plus 8 plus 4 plus 2 plus 1, which is 255.
- 4
Group bits for octal or hex
From the right, split the binary digits into groups of three for octal or four for hex, then read each group as a single digit.
- 5
Check the bit length
The number of binary digits tells you how many bits the value needs. Eight bits hold up to 255, sixteen up to 65535, and thirty-two up to about 4.3 billion.
Examples
Example 1: Decimal 255 in every base
- Value
- 255
- Input base
- Decimal (base 10)
| Step | Calculation | Result |
|---|---|---|
| Decimal | 255 | 255 |
| Binary | 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 | 11111111 |
| Octal | 3 x 64 + 7 x 8 + 7 | 377 |
| Hexadecimal | 15 x 16 + 15 | FF |
| Bit length | eight binary digits | 8 |
Result: 255 in decimal is FF in hexadecimal, 377 in octal and 11111111 in binary, which needs 8 bits.
Example 2: Hexadecimal FF back to decimal
- Value
- FF
- Input base
- Hexadecimal (base 16)
| Step | Calculation | Result |
|---|---|---|
| Hexadecimal input | FF | FF |
| Decimal | 15 x 16 + 15 | 255 |
| Binary | 1111 grouped with 1111 | 11111111 |
| Octal | 011 grouped with 111 and 111 | 377 |
Result: FF in hexadecimal is 255 in decimal, 11111111 in binary and 377 in octal.
Calculator
Prefer a full-width tool? Open the How To Convert Number Bases calculator page.
Common Mistakes
Reading the columns from the left
Place values grow to the left, so the rightmost digit is the base to the power zero. Numbering from the left inverts every place value.
Using a digit the base does not have
Binary only has 0 and 1, octal only 0 to 7. A 9 in an octal number is invalid, not a large digit.
Forgetting that hex letters are values
A stands for ten and F for fifteen. Treating them as letters rather than numbers breaks the arithmetic.
Grouping bits from the wrong end
Octal and hex grouping must start at the rightmost bit. Starting from the left misaligns every group when the bit count is not a multiple of three or four.
Dropping leading zeros before grouping
Padding a binary number to a multiple of three or four bits on the left keeps the groups aligned. Dropping the zeros silently changes the reading.
Confusing bit length with value
A bit length describes how many bits are needed, not the magnitude. Eight bits can hold any value from 0 to 255.
Assuming a base prefix is universal
0x for hex and 0b for binary are programming conventions, not mathematical notation. In written maths the base is a subscript.
FAQ
Why is hexadecimal used in computing?
Because four bits map to exactly one hex digit, so a byte is always two hex digits. That makes hex a compact, lossless shorthand for binary, unlike decimal which does not align to bit boundaries.
How do I convert decimal to binary by hand?
Divide by two repeatedly and collect the remainders, then read them in reverse. Alternatively subtract the largest power of two that fits and repeat.
What is the largest number in one byte?
255, which is 11111111 in binary. A byte has 256 possible values, counting from zero, so the largest is one less than 256.
Is 11 the same in every base?
No. It means three in binary, nine in decimal, eleven in base twelve and seventeen in hexadecimal. The base must always be stated.
Why does 0.1 plus 0.2 not equal 0.3 on a computer?
Binary cannot represent one tenth exactly, just as decimal cannot represent one third exactly. The stored value is the nearest binary fraction, and the tiny difference shows up in the last place.
What are octal numbers used for today?
Mainly Unix file permissions, where each digit encodes three permission bits for owner, group and others. Elsewhere hexadecimal has largely replaced octal.
References
- [1]Encyclopaedia Britannica, Binary number system — https://www.britannica.com/technology/binary-number-system
- [2]Wikipedia, Hexadecimal — https://en.wikipedia.org/wiki/Hexadecimal
- [3]Wikipedia, Radix — https://en.wikipedia.org/wiki/Radix