Free tool

Number base converter, binary, decimal, hex.

Type a number and see it in binary, octal, decimal and hexadecimal at once, plus any other base from 2 to 36. Numbers can be as long as you like, because nothing is rounded. Pick a bit length to see two's complement, turn on fractions, group the digits, and open the steps to see how one conversion is done by hand. A number that is also a character, like 65, is shown as text.

Two's complement

The steps

Options

A 0x, 0b or 0o in front sets the base for you. Spaces and underscores inside a number are ignored. Settings are remembered in this browser.

Converted in your browser. Nothing is sent anywhere.

How it works

Same number, different digits.

01 / Place value

Each digit has a weight

In base 10 the places are worth 1, 10, 100. In base 2 they are worth 1, 2, 4, 8. In base 16 they are worth 1, 16, 256.

02 / Exact

No rounding

Whole numbers use arbitrary-size integers, so 2 to the power of 64 comes out digit for digit, not as 1.8e19.

03 / Steps

Shown, not just answered

Open the steps to see the place values added up, or the divisions by the base and the remainders that make the answer.

Guide

How to convert between bases, with worked examples.

A number base converter rewrites one number using a different set of digits. Binary uses two digits, octal eight, decimal ten and hexadecimal sixteen, but the number itself does not change. This converter shows binary, octal, decimal and hex together, handles any base from 2 to 36, keeps every digit of very large numbers, and can show a number as a two's complement bit pattern of the length you choose. It answers binary to decimal, decimal to hex, hex to binary and every other pair in one box.

How to use the converter

  1. Type or paste the number into Number. The default is 255.
  2. Choose what you typed under From base: Binary, Octal, Decimal, Hexadecimal, or Other base for anything from 2 to 36. A 0x, 0b or 0o in front sets the base for you.
  3. Read the rows. Binary, Octal, Decimal and Hexadecimal are always there. The fifth row follows Other base row, which starts at 36.
  4. Press Copy beside a row for that answer, Copy all for every row, or Copy link for a link that opens with your number.
  5. Tick Group the digits to space binary and hex in fours and octal and decimal in threes. Untick Capital letters for a to f instead of A to F.
  6. Tick Fractions (a point) to convert a number such as 10.8 or 0.1, and set Places after the point.
  7. Set the Bit length to see two's complement, and open The steps to see one conversion by hand. Choose which with Show the steps to.

Binary to decimal

Each binary digit is worth a power of two, counting from the right: 1, 2, 4, 8, 16, 32 and so on. Add the values where the digit is 1. Take 101101: that is 32 + 8 + 4 + 1, which is 45. The steps panel lays this out as a table of digit, place value and digit times place value.

Decimal to hex, and decimal to binary

Going the other way, divide by the new base again and again and keep the remainders. For 45 to binary: 45 / 2 = 22 remainder 1, 22 / 2 = 11 remainder 0, 11 / 2 = 5 remainder 1, 5 / 2 = 2 remainder 1, 2 / 2 = 1 remainder 0, 1 / 2 = 0 remainder 1. Read the remainders from the bottom up and you get 101101. The same method gives hex with 16: 4660 / 16 = 291 remainder 4, 291 / 16 = 18 remainder 3, 18 / 16 = 1 remainder 2, 1 / 16 = 0 remainder 1, so 4660 is 0x1234.

Hex to binary, and back

One hex digit is exactly four binary digits, so you can convert in groups. 1101 is D and 0110 is 6, so 11010110 is D6 in hex, which is 13 x 16 + 6 = 214 in decimal. Octal works the same way with three bits per digit. That is why hex is the usual way to write binary compactly.

Two's complement

Computers store negative whole numbers in two's complement. Pick a bit length, then flip every bit of the positive number and add 1. For -5 in 8 bits: 5 is 00000101, flipped it is 11111010, and adding 1 gives 11111011, which is 0xFB. The same pattern read as unsigned is 251. The converter shows both readings and the range for the length you chose, and says so when a number does not fit.

BitsUnsigned rangeSigned range
80 to 255-128 to 127
160 to 65,535-32,768 to 32,767
320 to 4,294,967,295-2,147,483,648 to 2,147,483,647

Fractions and numbers that never end

A number with a point can be exact in one base and endless in another. 0.1 in decimal becomes 0.000110011001... in binary, a pattern that repeats forever, which is why 0.1 + 0.2 is not exactly 0.3 in most programming languages. The converter cuts the digits off after the number of places you set and tells you when it did. Multiplying the fraction by the new base and keeping the whole part, one digit at a time, is the method shown in the steps.

Very large numbers

Whole numbers are not rounded. 18446744073709551616, which is 2 to the power of 64, becomes 1 followed by sixteen zeros in hex. A number up to 20,000 digits long is accepted.

Letters, text and other bases

Bases above 10 use letters for the digits after 9: a is 10, b is 11 and z is 35, so base 36 uses every letter. In base 36, zz is 35 x 36 + 35, which is 1295. When the number is also a character code, the Character row shows it, so 65 is A. When a long hex number is made of UTF-8 bytes, the Bytes as text row shows the words. For a full text translator, use the binary translator.

Common problems

  • A digit is not allowed. The message names the character and its place. A 2 cannot appear in binary, and a g cannot appear in hex.
  • The number has a point and nothing happens. Tick Fractions first.
  • The hex answer looks wrong. Check the From base. The text 10 is 2 in binary, 8 in octal, 10 in decimal and 16 in hex.
  • A negative number. A minus sign works in any row. For the bit pattern a computer stores, use the two's complement box.

For colours, the hex to RGB converter turns a hex code into red, green and blue.

Questions

Good to know.

How do I convert binary to decimal?

Choose Binary under From base, paste the ones and zeros, and read the Decimal row. By hand, add the powers of two where there is a 1: 101101 is 32 + 8 + 4 + 1 = 45.

How do I convert decimal to hex?

Leave From base on Decimal and read the Hexadecimal row. By hand, divide by 16 and keep the remainders: 4660 gives 0x1234.

How big can the number be?

Up to 20,000 digits. Whole numbers are exact, with no rounding, so 18446744073709551616 converts digit for digit.

What is two's complement?

The way computers write negative whole numbers in a fixed number of bits. Flip the bits of the positive number and add 1. In 8 bits, -5 is 11111011.

Why do some fractions get cut off?

A fraction that ends in one base can repeat forever in another. 0.1 is endless in binary. The converter stops after the places you set and says it did.

What do 0x, 0b and 0o mean?

They are prefixes used in code for hex, binary and octal. Type one in front of a number and the converter sets From base for you.

Which bases can I use?

Any whole base from 2 to 36. Digits above 9 are the letters a to z.

Is my number sent anywhere?

No. The maths runs in your browser.