Appearance

Number Base Converter

/number-base-converter/

Input base
Convert to
Base 16

 

Related tools

Related posts

Comments

0/500

About this tool

When you need a number base converter

The decimal system we use every day is just a custom that probably comes from having ten fingers; computers store every value in binary, using only 0 and 1. Binary numbers get long and hard to read, so developers also use hexadecimal, which packs four binary digits into one character, and octal, which packs three. Memory addresses, the color code #FFFFFF, Linux file permissions like 644 and network subnet masks all call for moving between bases, every day in development and in computing courses.

Read moreShow less

Binary and octal conversion are also staples of IT certification exams and of computer architecture and digital logic classes. Pick the input base and the target base with the 2, 8, 10 and 16 buttons (it starts at decimal to hexadecimal, and bases 3 to 36 are under Other), enter a number, and the tool shows the target value large with the other common bases below it, which is handy for checking answers worked out by hand or confirming a constant before putting it in code.

How base conversion works, and why BigInt keeps it exact

In any base, a number is the sum of each digit times its place value. Binary 1010 is 8 + 0 + 2 + 0, decimal 10, and octal 777 is 7 × 64 + 7 × 8 + 7 = 511. To convert a decimal number to another base, divide repeatedly by the base and read the remainders in reverse. Dividing 255 by 2 repeatedly gives remainders that are all 1, so it is 11111111; grouping that in threes (11 111 111) gives octal 377, and in fours (1111 1111) gives hexadecimal FF. That is why conversion among binary, octal and hexadecimal needs nothing more than regrouping digits.

The tool builds the value by reading the input one digit at a time and repeating 'value so far × base + this digit', and gets the output digits from JavaScript BigInt's toString. There is a reason it avoids ordinary Numbers: a JavaScript Number is a 64-bit float and cannot represent integers exactly above 2^53 (9007199254740992). Number('9007199254740993') actually ends in 2, but here 9007199254740993 converts exactly, last digit included, to hexadecimal 20000000000001. The largest unsigned 64-bit integer, 18446744073709551615, is FFFFFFFFFFFFFFFF in hex and 3W5E11264SGSF in base 36.

Bases above 10 write digits of 10 and up as letters. In hexadecimal A to F stand for 10 to 15, and base 36 uses all of 0 to 9 and A to Z, so Z is 35. Base-36 ZZ is 35 × 36 + 35 = 1295. Base 36 is used for short IDs and URL shorteners; even 2147483647, over 2.1 billion, is just six characters in base 36: ZIK0ZJ.

Using the converter as a developer or student

In development work you can paste values with their prefixes. With hexadecimal as the input base it accepts 0xFF, with octal 0o777 and with binary 0b1010, the same notation you use in code, and values split with spaces or underscores, such as 1111 1111 or 0b1111_1111, are read with the spaces and underscores ignored. Entering the Linux permission 644 as octal gives binary 110100100; read in threes as 110, 100 and 100, it plainly means read and write for the owner and read for the group and others. The web color FFFFFF is 16777215 in decimal, confirming that 24-bit color has 16777216 possible colors counting 0.

Students can work through the division and regrouping by hand and then compare. When either base is above 10 an Uppercase option appears; it is on by default, so hex appears as FF, and turning it off gives lowercase ff. Swap flips the two bases and turns the result into the new input, which makes checking the reverse easy. Copy copies every result on screen at once, one labeled line per base.

Two's complement, fractions and input errors

Negative numbers take a leading -, and the results carry the sign too: -42 is binary -101010 and hex -2A. Keep in mind that this differs from two's complement, the way computers actually store negative numbers. In 8-bit two's complement -1 is 11111111, but entering 11111111 as binary here reads it as the unsigned value 255. If you need a two's complement value, fix the bit width and work it out yourself.

Only integers are converted, so numbers with a decimal point such as 0.1 are treated as errors. Decimal 0.1 is an endlessly repeating fraction in binary, which is also why 0.1 + 0.2 is not exactly 0.3 in programming languages. A digit that does not exist in the chosen base also causes an error; typical cases are a 2 in binary input, or entering 0xFF while the input base is still decimal. Calculations run in this browser and stay exact with BigInt however long the number. Your input and base choices are kept in this browser for next time and cleared with Reset, and the last 5 entries that produced a result can be reloaded from Recent below the tool.

FAQ

How do I convert binary to decimal?

Choose base 2 as the input base and enter 1010 to get decimal 10, octal 12 and hex A together. By hand, multiply the digits from the right by place values 1, 2, 4 and 8 and add them; 1010 is 8 + 2, which is 10.

How do I convert decimal to hexadecimal?

Leave the input base at decimal and enter the number; the result appears on the hexadecimal line. By hand, divide by 16 repeatedly and read the remainders in reverse, writing 10 to 15 as A to F. 255 is FF in hex and 100 is 64.

How do octal numbers work?

Each octal digit is a power of 8. 777 is 7 × 64 + 7 × 8 + 7 = 511, and grouping binary digits in threes and turning each group into 0 to 7 also gives octal. Choose octal as the input base to see the other bases at once.

Are very large numbers converted exactly?

Yes. Calculation uses BigInt, so every digit is exact with no length limit. Values such as 9007199254740993, which ordinary JavaScript numbers cannot hold exactly, convert correctly.

Does it show negative numbers in two's complement?

No. Negative numbers are shown with a minus sign, as in -101010. Two's complement depends on the bit width, so choose a width such as 8 or 32 bits and calculate it yourself.

Can it convert numbers with a decimal point?

Only integers are converted. A decimal point produces an error saying the input contains a digit not valid in that base. Decimal fractions often repeat endlessly in binary and need a different method.