Lelifi·tools

Base Converter

Base conversion rewrites a number without changing its value. Decimal 5,678 becomes 162E in base 16, 13056 in base 8 and 1011000101110 in base 2, and every digit comes from one division by the target base, with the remainders read from the bottom up.

Type a whole number, a fraction or a negative value, then pick the base it is written in and the base you want.

Type a number, pick the base it is written in and the base you want, and get the converted value with the digits, the division steps and a round-trip check.

By the Lelifi editors ·

Key takeaways

5,678 in base 16: four digits, four weights162E16 to the 3rd16 squared1611 x 4,0966 x 2562 x 1614 x 14,096 + 1,536 + 32 + 14 = 5,678The same total, written with different symbols on different place values.Decimal 5,678 and hex 162E name one quantity.
The hex digits of 5,678 on their place values. Each column is worth sixteen times the column to its right, and the four products add back to 5,678.
Thirteen bits, padded to four groups of fourbinarypaddedhex digit1 0110 0010 11100001 0110 0010 1110162EEach hex digit owns four bits, so 0001 0110 0010 1110 becomes 162E with no division.The two extra zeros on the left pad the number to a whole number of digits.Grouping by threes instead gives the octal form 13056.
The thirteen bits of 5,678 padded to sixteen and split into four-bit groups. Reading each group as one hex digit gives 162E.
On this page
  1. What a base converter changes
  2. Decimal 5,678 into hex, one division at a time
  3. Fractions after the radix point
  4. Bit grouping makes hex and octal shortcuts
  5. Negative numbers and fixed widths
  6. Where each base turns up in daily work
  7. Four checks that catch a wrong conversion
  8. What the browser can and cannot do

What a base converter changes

A base is the number of symbols a place-value system uses. Base 10 has ten digits, and each place is worth ten times the place to its right. Base 16 needs sixteen symbols, so it adds six letters to the ten digits: A is 10, B is 11, and the run ends at F for 15. This converter covers every base from 2 to 36, with the alphabet running 0 to 9 and then A to Z, which puts Z at 35.

Changing the base does not change the number. Decimal 5,678, hex 162E, octal 13056 and binary 1011000101110 all count the same quantity. Only the spelling changes.

Two operations do all the work. Expansion multiplies each digit by its place value and adds the results, which turns a number in any base into base 10. Repeated division by the target base turns a base 10 number into any other base, one digit at a time.

It also handles two cases that many simple converters drop: a fractional part after the radix point, and a minus sign in front.

Decimal 5,678 into hex, one division at a time

The rule for whole numbers is short. Divide by the target base, keep the remainder as the next digit, then repeat with the quotient until the quotient reaches zero. Read the remainders from the last one back to the first.

DivisionQuotientRemainderDigit
5,678 / 1635414E
354 / 162222
22 / 16166
1 / 16011

Reading bottom to top gives 162E. The same ladder with 8 in place of 16 ends at 13056, and with 2 in place of 16 it ends at 1011000101110.

Expansion checks the result without trusting the tool. The leftmost digit sits on 16 cubed, which is 4,096. Next comes 6 on 16 squared, which is 256, then 2 on 16, then E on 1. The sum is 1 x 4,096 + 6 x 256 + 2 x 16 + 14 = 4,096 + 1,536 + 32 + 14 = 5,678. Because the sum has to land on the number you started with, any slip in the ladder shows up here at once.

Octal checks the same way with powers of 8. The digits 1, 3, 0, 5, 6 stand on 4,096, 512, 64, 8 and 1, so 1 x 4,096 + 3 x 512 + 0 x 64 + 5 x 8 + 6 = 4,096 + 1,536 + 40 + 6 = 5,678. Binary needs the longest expansion of the three, with thirteen place values from 4,096 down to 1.

Fractions after the radix point

For the part to the right of the point, the loop flips. Multiply the fraction by the target base, write down the whole part of the result, keep the new fraction, and repeat. Stop when the fraction reaches zero or when you have as many digits as you need.

Take 0.6875 in decimal and convert it to binary. Step one: 0.6875 x 2 = 1.375, so the digit is 1 and 0.375 is left over. Step two: 0.375 x 2 = 0.75, so the digit is 0. Step three: 0.75 x 2 = 1.5, digit 1. Step four: 0.5 x 2 = 1.0, digit 1, and nothing is left. The digits in the order produced give 0.1011.

StepMultiplyDigitLeft over
10.6875 x 2 = 1.37510.375
20.375 x 2 = 0.7500.75
30.75 x 2 = 1.510.5
40.5 x 2 = 1.010

Check it with place values. The first place is worth 0.5, the third 0.125 and the fourth 0.0625, and 0.5 + 0.125 + 0.0625 = 0.6875.

Most fractions do not stop. Decimal 0.1 in binary runs 0.000110011001 and keeps going, because 1/10 in lowest terms has a denominator of 10, and 10 carries a factor of 5. A fraction terminates in base b only when its denominator, in lowest terms, is built from prime factors of b. Base 2 offers only the factor 2, so halves, quarters and eighths stop while tenths and fifths run forever. Base 10 offers 2 and 5, which is why 1/10 and 1/4 both stop there but 1/3 does not.

Binary floating point inherits that behavior. The 0.1 you type into a computer is stored as the nearest double, and adding 0.2 to it usually gives 0.30000000000000004. That is not broken arithmetic. It is the same repeating fraction showing up inside a fixed 53-bit field.

Bit grouping makes hex and octal shortcuts

Sixteen is 2 to the fourth power, so one hex digit maps to exactly four bits. Eight is 2 cubed, so one octal digit maps to exactly three bits. That mapping is why memory dumps are read in hex rather than binary: the strings stay short, and the conversion needs no division at all.

Take 5,678, which is 1011000101110 in binary, thirteen bits. Pad on the left to a multiple of four: 0001 0110 0010 1110. Each group of four becomes one hex digit, since 0001 is 1, 0110 is 6, 0010 is 2 and 1110 is 14, which is E. The answer appears as 162E without a single division.

Octal groups by three from the same right-hand edge. The thirteen bits become 001 011 000 101 110, which reads 1, 3, 0, 5, 6, so the octal form is 13056. Padding always goes on the left, because place values grow to the left.

The shortcut only works when one base is a power of the other. Hex to binary and octal to binary are free. Decimal to hex, or base 12 to base 36, needs the arithmetic loops described above. A converter that offers both routes is useful for exactly that reason: the fast route confirms the slow one.

Negative numbers and fixed widths

A converter can put a minus sign in front and call it done: minus five in base 2 reads -101. Hardware has no minus sign and no infinite tape, only a fixed number of bits, so it stores a pattern instead. In 8-bit two's complement, 5 is 00000101 and -5 is 11111011.

The recipe is to invert every bit and then add one. 00000101 becomes 11111010, and adding 1 gives 11111011. Read as an unsigned number that pattern is 251, and 251 + 5 = 256, which wraps to 0 in eight bits. The wrap is the point of the trick, because addition then works without a special case for negative operands.

Width matters. Minus five in 16 bits is 1111111111111011, and in 32 bits it carries twenty-nine leading ones. A debugger that shows FFFFFFFB is reporting -5 in a 32-bit register, while FFFB is the same value in a 16-bit one. Reading either pattern as a plain hex number gives 4,294,967,291 or 65,531, which is why the width has to travel with the number.

This page prints the sign and the magnitude, not a width pattern, because width is not one of its inputs. If you need the pattern for a register, convert the positive value, invert the bits, add one, and pad to the width in use.

Where each base turns up in daily work

Each base survives because it fits a job. The table lists the ones you are likely to meet, with a real example of each.

BaseExampleSymbolsWhere you meet it
210110001011100 and 1bit flags, subnet masks, logic gates
807550 to 7POSIX file permissions
16162E0 to 9, A to Fmemory addresses, byte dumps, color codes
32MZXW6===A to Z, 2 to 7RFC 4648 base32 encoding
364DQ0 to 9, A to Zshort links and coupon codes

The octal line is the one people hit without noticing. A file mode of 0755 packs three permission bits into each digit: 7 is read, write and execute for the owner, and 5 is read and execute for the group and for everyone else. The same mode in decimal is 493, which is what a program sees when it reads the number rather than the notation. The POSIX chmod specification defines that octal form.

Base 36 with 0 to 9 and A to Z is the widest set that stays case-insensitive, which makes it safe in a link that people retype or read aloud. Three symbols reach 46,655, because 35 x 1,296 + 35 x 36 + 35 = 46,655, so ZZZ is the top of the three-symbol range.

Base 32 and base 64 are not extensions of this page's alphabet. RFC 4648 sets base32 as A to Z followed by 2 to 7, and base64 as A to Z, a to z, 0 to 9, plus, and slash, so a base64 string is not a base 64 number in the 0 to 9 then A to Z sense. This converter stops at 36.

Four checks that catch a wrong conversion

Every conversion can be tested in a few seconds.

First, no digit may reach the base. Base 2 allows only 0 and 1, so a 2 in the input is invalid, and base 16 allows F but not G. A converter that accepts an out-of-range digit is guessing at what you meant.

Second, the digit count is bounded. A number with n digits in base b is at least b to the power n minus 1 and less than b to the power n. Decimal 5,678 needs thirteen binary digits because 2 to the 12th is 4,096 and 2 to the 13th is 8,192, so 4,096 is less than or equal to 5,678 and 5,678 is less than 8,192. An answer with twelve bits is too small and one with fourteen is too large.

Third, convert the result back. A round trip that returns the starting value is strong evidence, and it catches a dropped digit that a spot check would miss.

Fourth, compare the last digit with the remainder. Dividing 5,678 by 16 leaves 14, and the last hex digit is E, which is 14. In base 8 the remainder is 6, and the last octal digit is 6. If those two numbers disagree, one of them is wrong, and the disagreement usually points at an arithmetic slip rather than at the base.

What the browser can and cannot do

Whole numbers here are converted with long division on the digits themselves, so the integer part is exact at any length, including inputs far past the 53-bit limit of a JavaScript number. A 30-digit decimal converts digit for digit.

The fractional part is different. It is carried in ordinary double precision and cut at twelve digits, so 0.1 in base 2 shows 0.000110011001. That is a cut, not a round, and the next digit would be 1. Twelve digits are enough to size a resistor or read a sensor, and not enough to claim an exact value for a fraction that never terminates.

Speed has a limit too. Inputs of several thousand digits run through the division loop one remainder at a time, which a browser handles slowly on a phone. For everyday work the numbers are short enough that the delay is invisible.

Bases above 36 are left out on purpose. Once you pass Z, there is no single alphabet that every system agrees on, so a converter that accepts base 64 without asking which alphabet it means will produce strings that other tools read differently. If you need base32 or base64, use a tool built for that encoding.

Frequently asked questions

How do I convert 5,678 to hexadecimal?

Divide by 16 and keep the remainders. 5,678 divided by 16 gives 354 with 14 left over, which is E. Then 354 divided by 16 gives 22 with 2 left, 22 divided by 16 gives 1 with 6 left, and 1 divided by 16 gives 0 with 1 left. Reading the remainders from the last to the first gives 162E.

What is 255 in binary?

11111111. Eight ones add up to 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, which is also 2 to the 8th minus 1. That is why 255 is the largest value an 8-bit byte holds.

What is FFFF in decimal?

65,535. Each F is 15, so the four places run 15 x 4,096 + 15 x 256 + 15 x 16 + 15 = 61,440 + 3,840 + 240 + 15 = 65,535, which is 16 to the 4th minus 1.

How do I turn a decimal fraction into binary?

Multiply by 2, record the whole part, and keep the remainder. For 0.6875 the doubling steps give 1.375, then 0.75, then 1.5, then 1.0. The whole parts read 1, 0, 1, 1 in that order, so the answer is 0.1011.

Why does 0.1 repeat in binary?

Because 1/10 in lowest terms has 10 in the denominator, and 10 has a factor of 5. Base 2 can only divide by 2, so the division never comes out even. Binary 0.1 is 0.000110011001 and continues without stopping.

What is 0755 in decimal?

493. The digits are 7, 5 and 5 on place values of 64, 8 and 1, so 7 x 64 + 5 x 8 + 5 = 448 + 40 + 5 = 493. As a file mode, 7 is read, write and execute for the owner, and 5 is read and execute for the other two classes of user.

Can the converter handle negative numbers?

Yes, it prints the minus sign and converts the magnitude, so minus five is -101 in binary. A register pattern is a different question: in 8-bit two's complement, minus five is 11111011, which is 251 read as an unsigned number.

Which bases does the calculator support?

Every base from 2 to 36. The symbols are 0 to 9 for values 0 to 9 and A to Z for values 10 to 35, so Z is the digit for 35 and cannot appear in any base of 35 or lower.

What is 13056 in decimal?

5,678. Read as octal, the digits stand on 4,096, 512, 64, 8 and 1, so 1 x 4,096 + 3 x 512 + 5 x 8 + 6 = 4,096 + 1,536 + 40 + 6 = 5,678.

How many bits does 5,678 need?

Thirteen. 2 to the 12th is 4,096, which is not enough to hold 5,678, and 2 to the 13th is 8,192, which is. Written out, 5,678 is 1011000101110, and that string is thirteen characters long.

What is base 36 used for?

Short identifiers that people can retype. With 36 symbols, three characters cover 46,656 values, from 0 to ZZZ, since 36 to the 3rd is 46,656. Links and coupon codes use it because letters and digits work in any case and survive being read aloud.

Is base 64 just base 36 with more letters?

No. Base 64 needs 64 symbols, so it runs past Z into lowercase and adds two punctuation marks. RFC 4648 sets the alphabet as A to Z, a to z, 0 to 9, plus and slash, which is a different order from this page's 0 to 9 then A to Z.

How can I check a conversion by hand?

Expand the answer. For 162E, that is 1 x 4,096 + 6 x 256 + 2 x 16 + 14 = 4,096 + 1,536 + 32 + 14 = 5,678. If the total matches the number you started with, the digits are right.

Does a leading zero change the value?

No. 0755 and 755 both equal 493 in decimal. The leading zero marks the number as octal in many programming languages, and inside a fixed width it pads the value out to the full number of bits.

Spotted a wrong number or a broken result?

More Math tools

See all Math tools

Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.